Join in the conversation!
Pick your username
Post in Forums
Create a Profile
Upload Pictures
Make Polls
Keep a Journal
Meet Friends
Have Fun
It's FREE!
Sign Up!
Forum Index: Computers & Internet: Web Design & Coding
Script to open links in new window without "target='_blank'"
Reply to Topic
AuthorMessage
Pages: 1 2 · >>
New Post! May 13, 2009 @ 22:17:24#1
Lili
Secretly Ridiculous


Über-Monkey+
59044 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?

1 minutes ago
Amazon.com goodies - Books - Movies - Electronics
New Post! May 13, 2009 @ 22:42:53#2
young_nick
The Dude


TFS Monkey+
44075 points


Send PM


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

Which CMS are you using?

On March 20, 2010
New Post! May 13, 2009 @ 23:04:08#3
El_Tino
booyaka!

Founder
Bogey Man
78392 points


Send PM


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

Put this in the page header.

<BASE target="_blank">

On March 19, 2010
New Post! May 13, 2009 @ 23:27:32#4
Lili
Secretly Ridiculous


Über-Monkey+
59044 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!

1 minutes ago
New Post! May 13, 2009 @ 23:30:26#5
El_Tino
booyaka!

Founder
Bogey Man
78392 points


Send PM


30/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

On March 19, 2010
New Post! May 13, 2009 @ 23:33:09#6
Lili
Secretly Ridiculous


Über-Monkey+
59044 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.
1 minutes ago
New Post! May 13, 2009 @ 23:41:48#7
Lili
Secretly Ridiculous


Über-Monkey+
59044 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.

1 minutes ago
New Post! May 13, 2009 @ 23:44:33#8
El_Tino
booyaka!

Founder
Bogey Man
78392 points


Send PM


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

try this

Code:


<script>
if(top.location != document.location) {
document.write('<BASE target="_blank">');
}
</script>
On March 19, 2010
New Post! May 13, 2009 @ 23:46:46#9
Lili
Secretly Ridiculous


Über-Monkey+
59044 points


Send PM


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

cool! is that javascript?

1 minutes ago
New Post! May 13, 2009 @ 23:49:10#10
El_Tino
booyaka!

Founder
Bogey Man
78392 points


Send PM


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

yeppers

On March 19, 2010
New Post! May 13, 2009 @ 23:49:31#11
Lili
Secretly Ridiculous


Über-Monkey+
59044 points


Send PM


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

I feel like I should pay you or something, lol

1 minutes ago
New Post! May 13, 2009 @ 23:51:43#12
El_Tino
booyaka!

Founder
Bogey Man
78392 points


Send PM


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

don't worry about it.

On March 19, 2010
New Post! May 13, 2009 @ 23:53:21#13
El_Tino
booyaka!

Founder
Bogey Man
78392 points


Send PM


30/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]

On March 19, 2010
New Post! May 14, 2009 @ 00:00:52#14
Lili
Secretly Ridiculous


Über-Monkey+
59044 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!

1 minutes ago
New Post! May 14, 2009 @ 00:03:47#15
El_Tino
booyaka!

Founder
Bogey Man
78392 points


Send PM


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

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

On March 19, 2010
Reply to Topic<< Previous Topic | Next Topic >>
Pages: 1 2 · >>

TFS Time: Sat 20 Mar 2010 12:44 pm CDT
Copyright © 2004-2010 Funky Llama Productions, LLC   |   Home   |   Contact   |   Privacy Policy   |   Terms of Service   |   Top of Page
The Forum Site - Your premier source for everything
Hate ads?