Post in Forums
Create a Profile
Upload Pictures
Make Polls
Keep a Journal
Meet Friends
Have Fun
It's FREE!
Sign Up!
Avoid the cold & the crowds - Buy your Christmas gifts at Amazon.com
Forum Index > Computers & Internet > Web Design & Coding
>> Script to open links in new window without "target='_blank'"
Reply to Topic
Search Topic
Subscription
Author Message
Pages: 1 2 · >>
New Post! May 13, 2009 @ 22:17:24#1
Lili
Silly Lili


Über-Monkey+
52664 points


Send PM


27/F/Sunshine Land, California
Join Date: Apr 2005

I need a script to open links in a new window without having to edit the html links themselves in any way. I've found plenty of javascript scripts to isolate links with certain classes are attributes, but I can't edit in classes and attributes (well, I *could*, but it's messy and complicated with this CMS, so I'd really prefer to not get into all that), so I need it to just open all links in a new window. Can you help me?





"Give a man a fish, he eats for a day. Teach a man to fish, he eats for a lifetime."
On November 21, 2009
New Post! May 13, 2009 @ 22:42:53#2
young_nick
Jesus Impersonator


TFS Monkey+
41664 points


Send PM


19/M/Auckland, New Zealand
Join Date: Nov 2005

Which CMS are you using?




my Last.fm
On November 21, 2009
New Post! May 13, 2009 @ 23:04:08#3
eL_TinO
booyaka!

Founder
Bogey Man
75147 points


Send PM


29/M/Las Cruces, New Mexico
Join Date: Oct 2004

Put this in the page header.

<BASE target="_blank">




- Every time you toke up, God kills a Mexican
- Buy stuff at Amazon
On November 21, 2009
New Post! May 13, 2009 @ 23:27:32#4
Lili
Silly Lili


Über-Monkey+
52664 points


Send PM


27/F/Sunshine Land, California
Join Date: Apr 2005

wow, who knew it could be so simple! lol
I've been looking online, and find pages and pages of people struggling over javascript code and all it takes is that!





"Give a man a fish, he eats for a day. Teach a man to fish, he eats for a lifetime."
On November 21, 2009
New Post! May 13, 2009 @ 23:30:26#5
eL_TinO
booyaka!

Founder
Bogey Man
75147 points


Send PM


29/M/Las Cruces, New Mexico
Join Date: Oct 2004

Now, this will open all the links in a new window, not just external links.

If you want a particular link to open in the same window you have to add the target=_self




- Every time you toke up, God kills a Mexican
- Buy stuff at Amazon
On November 21, 2009
New Post! May 13, 2009 @ 23:33:09#6
Lili
Silly Lili


Über-Monkey+
52664 points


Send PM


27/F/Sunshine Land, California
Join Date: Apr 2005

young_nick said:

Which CMS are you using?


Drupal. I really like Drupal in every way except theming. Theming is not their strong point. In order to change the output, you have to go into the module core code, find the function that's producing the HTML, copy it to a separate file, and rename it along specific guidelines, and place that in your default theme directory. And God forbid there are multiple modules producing your page layout. XOOPS was great for theming, they used smarty tags, so all the theming was separate from the core code, it was awesome. But they suck in just about every other way, so it's a give a take, you have to weigh your priorities.




"Give a man a fish, he eats for a day. Teach a man to fish, he eats for a lifetime."
On November 21, 2009
New Post! May 13, 2009 @ 23:41:48#7
Lili
Silly Lili


Über-Monkey+
52664 points


Send PM


27/F/Sunshine Land, California
Join Date: Apr 2005

Ok, so now I need a php code that basically says, "if top.href != hostname, print <BASE target="_blank">"

I have some pages that are going to be in an iframe, and I need the links to only open in a new window if a page is in an iframe.





"Give a man a fish, he eats for a day. Teach a man to fish, he eats for a lifetime."
On November 21, 2009
New Post! May 13, 2009 @ 23:44:33#8
eL_TinO
booyaka!

Founder
Bogey Man
75147 points


Send PM


29/M/Las Cruces, New Mexico
Join Date: Oct 2004

try this

Code:


<script>
if(top.location != document.location) {
document.write('<BASE target="_blank">');
}
</script>



- Every time you toke up, God kills a Mexican
- Buy stuff at Amazon
On November 21, 2009
New Post! May 13, 2009 @ 23:46:46#9
Lili
Silly Lili


Über-Monkey+
52664 points


Send PM


27/F/Sunshine Land, California
Join Date: Apr 2005

cool! is that javascript?





"Give a man a fish, he eats for a day. Teach a man to fish, he eats for a lifetime."
On November 21, 2009
New Post! May 13, 2009 @ 23:49:10#10
eL_TinO
booyaka!

Founder
Bogey Man
75147 points


Send PM


29/M/Las Cruces, New Mexico
Join Date: Oct 2004

yeppers




- Every time you toke up, God kills a Mexican
- Buy stuff at Amazon
On November 21, 2009
New Post! May 13, 2009 @ 23:49:31#11
Lili
Silly Lili


Über-Monkey+
52664 points


Send PM


27/F/Sunshine Land, California
Join Date: Apr 2005

I feel like I should pay you or something, lol





"Give a man a fish, he eats for a day. Teach a man to fish, he eats for a lifetime."
On November 21, 2009
New Post! May 13, 2009 @ 23:51:43#12
eL_TinO
booyaka!

Founder
Bogey Man
75147 points


Send PM


29/M/Las Cruces, New Mexico
Join Date: Oct 2004

don't worry about it.




- Every time you toke up, God kills a Mexican
- Buy stuff at Amazon
On November 21, 2009
New Post! May 13, 2009 @ 23:53:21#13
eL_TinO
booyaka!

Founder
Bogey Man
75147 points


Send PM


29/M/Las Cruces, New Mexico
Join Date: Oct 2004

Here's a way to set external and internal links differently if you wanted to.

link [forums.devshed.com]




- Every time you toke up, God kills a Mexican
- Buy stuff at Amazon
On November 21, 2009
New Post! May 14, 2009 @ 00:00:52#14
Lili
Silly Lili


Über-Monkey+
52664 points


Send PM


27/F/Sunshine Land, California
Join Date: Apr 2005

Thanks, this has solved my last obstacle to getting this to work

I'm migrating my site from xoops to drupal, and I have to recreate various aspects of my xoops site within drupal, one of which are my google modules, which are iframes on the iGoogle homepage. So now that the links will open in a new window, it'll work just fine

Awesome!





"Give a man a fish, he eats for a day. Teach a man to fish, he eats for a lifetime."
On November 21, 2009
New Post! May 14, 2009 @ 00:03:47#15
eL_TinO
booyaka!

Founder
Bogey Man
75147 points


Send PM


29/M/Las Cruces, New Mexico
Join Date: Oct 2004

sounds complicated, and I hope you get it all figured out!




- Every time you toke up, God kills a Mexican
- Buy stuff at Amazon
On November 21, 2009
Reply to Topic<< Previous Topic | Next Topic >>
Pages: 1 2 · >>

Top

TFS Time: Sat 21 Nov 2009 07:09 am CST
Copyright © 2004-2009 Funky Llama Productions, LLC   |   Home   |   Contact   |   Privacy Policy   |   Terms of service

The Forum Site - Your premier source for everything LOGIN REGISTER