The Forum Site - Join the conversation
Forums: Technology & Internet:
Web Design & Coding

Script to open links in new window without "target='_blank'"

Reply to Topic
AuthorMessage
Pages: 1 2 · >>
Lili On July 12, 2019
....................





Sunshine Land,
#1New Post! May 13, 2009 @ 22:17:24
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?
young_nick On December 11, 2010
The Dude





Auckland, New Zealand
#2New Post! May 13, 2009 @ 22:42:53
Which CMS are you using?
El_Tino On July 24, 2019
booyaka!





Albuquerque, New Mexico
#3New Post! May 13, 2009 @ 23:04:08
Put this in the page header.

<BASE target="_blank">
Lili On July 12, 2019
....................





Sunshine Land,
#4New Post! May 13, 2009 @ 23:27:32
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!
El_Tino On July 24, 2019
booyaka!





Albuquerque, New Mexico
#5New Post! May 13, 2009 @ 23:30:26
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
Lili On July 12, 2019
....................





Sunshine Land,
#6New Post! May 13, 2009 @ 23:33:09
@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.
Lili On July 12, 2019
....................





Sunshine Land,
#7New Post! May 13, 2009 @ 23:41:48
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.
El_Tino On July 24, 2019
booyaka!





Albuquerque, New Mexico
#8New Post! May 13, 2009 @ 23:44:33
try this

Code:

<script>
if(top.location != document.location) {
document.write('<BASE target="_blank">');
}
</script>
Lili On July 12, 2019
....................





Sunshine Land,
#9New Post! May 13, 2009 @ 23:46:46
cool! is that javascript?
El_Tino On July 24, 2019
booyaka!





Albuquerque, New Mexico
#10New Post! May 13, 2009 @ 23:49:10
yeppers
Lili On July 12, 2019
....................





Sunshine Land,
#11New Post! May 13, 2009 @ 23:49:31
I feel like I should pay you or something, lol
El_Tino On July 24, 2019
booyaka!





Albuquerque, New Mexico
#12New Post! May 13, 2009 @ 23:51:43
don't worry about it.
El_Tino On July 24, 2019
booyaka!





Albuquerque, New Mexico
#13New Post! May 13, 2009 @ 23:53:21
Here's a way to set external and internal links differently if you wanted to.

https://forums.devshed.com/javascript-development-115/base-target-using-javascript-44087.html
Lili On July 12, 2019
....................





Sunshine Land,
#14New Post! May 14, 2009 @ 00:00:52
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!
El_Tino On July 24, 2019
booyaka!





Albuquerque, New Mexico
#15New Post! May 14, 2009 @ 00:03:47
sounds complicated, and I hope you get it all figured out!
Reply to Topic<< Previous Topic | Next Topic >>
Pages: 1 2 · >>

1 browsing (0 members - 1 guest)

Quick Reply
Be Respectful of Others

      
Subscribe to topic prefs

Similar Topics
    Forum Topic Last Post Replies Views
New posts   Society & Lifestyles
Fri Aug 13, 2010 @ 00:56
54 4857
New posts   Site Support
Mon Mar 30, 2009 @ 16:42
6 557
New posts   Technology & Internet
Wed Nov 26, 2008 @ 18:39
9 724
New posts   Science
Thu Apr 10, 2008 @ 14:58
7 1041
New posts   Feedback & Suggestions
Sat Sep 10, 2005 @ 17:09
4 1056