Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 03-05-2008, 02:00 PM
gridsix's Avatar
gridsix gridsix is offline
Contributing Member
 
Join Date: 03-04-08
Posts: 251
iTrader: 1 / 100%
Forcing external links to open in a new window

Anyone know of a way to make all external links on a given site open in a new window? Maybe via css, or the htaccess file?

Thanks much!
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 03-05-2008, 02:08 PM
impius's Avatar
impius impius is offline
Contributing Member
 
Join Date: 01-28-08
Posts: 150
iTrader: 0 / 0%
Lightbulb

http://www.htmlcodetutorial.com/link...amsupp_72.html

This is pretty simple...
 
Reply With Quote
  #3  
Old 03-05-2008, 02:13 PM
gridsix's Avatar
gridsix gridsix is offline
Contributing Member
 
Join Date: 03-04-08
Posts: 251
iTrader: 1 / 100%
And that code will automatically replace all external links? It looks like I have to edit each link individually...
 
Reply With Quote
  #4  
Old 03-05-2008, 02:17 PM
impius's Avatar
impius impius is offline
Contributing Member
 
Join Date: 01-28-08
Posts: 150
iTrader: 0 / 0%
Ohhhhhh...didnt catch that...I dont think that is possible...would be nice though
 
Reply With Quote
  #5  
Old 03-05-2008, 02:18 PM
gridsix's Avatar
gridsix gridsix is offline
Contributing Member
 
Join Date: 03-04-08
Posts: 251
iTrader: 1 / 100%
Sorry for leaving that detail out...

You sure? seems like a lot of scripts have that built in...
 
Reply With Quote
  #6  
Old 03-05-2008, 02:22 PM
impius's Avatar
impius impius is offline
Contributing Member
 
Join Date: 01-28-08
Posts: 150
iTrader: 0 / 0%
I am not positive...but typically you have to call a script from within the link.

I would definetly be interested if someone had a way.
 
Reply With Quote
  #7  
Old 03-06-2008, 12:55 AM
Boogle's Avatar
Boogle Boogle is offline
Contributing Member
 
Join Date: 09-03-07
Location: England
Posts: 649
iTrader: 0 / 0%
You could use Javascript to iterate through all the <a href's></a> within the page when it loads. If they are an external link then add the attribute, 'target="_Blank"

Boog's
 
Reply With Quote
  #8  
Old 03-06-2008, 07:37 AM
gridsix's Avatar
gridsix gridsix is offline
Contributing Member
 
Join Date: 03-04-08
Posts: 251
iTrader: 1 / 100%
Got an example of the code?
 
Reply With Quote
  #9  
Old 03-07-2008, 01:32 AM
nasty.web nasty.web is offline
v7n Mentor
 
Join Date: 07-24-06
Posts: 688
iTrader: 1 / 100%
New-Window Links in a Standards-Compliant World
 
Reply With Quote
  #10  
Old 03-07-2008, 01:43 AM
Boogle's Avatar
Boogle Boogle is offline
Contributing Member
 
Join Date: 09-03-07
Location: England
Posts: 649
iTrader: 0 / 0%
good find, Nasty that's just about what i was thinking, i think that method's better than the one i would have used though!

Boog's
 
Reply With Quote
  #11  
Old 03-07-2008, 07:32 AM
gridsix's Avatar
gridsix gridsix is offline
Contributing Member
 
Join Date: 03-04-08
Posts: 251
iTrader: 1 / 100%
That article states that i need to edit every link on the site; am i missing something?

THanks.
 
Reply With Quote
  #12  
Old 03-07-2008, 07:44 AM
nasty.web nasty.web is offline
v7n Mentor
 
Join Date: 07-24-06
Posts: 688
iTrader: 1 / 100%
Quote:
Originally Posted by gridsix View Post
That article states that i need to edit every link on the site; am i missing something?

THanks.
Not neccesarily so. You can change externalLinks function to check href attributes, for example:

Code:
function externalLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) { var anchor = anchors[i]; if (anchor.getAttribute("href") && (anchor.getAttribute("href").indexOf("http://www.yourdomain.com") == -1)) // anchor.target = "_blank"; } }
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to open a new window in Adsense? minbak Contextual Networks 19 12-01-2007 09:42 AM
blogger, open image in window script? littlephoenix Blogging Forum 2 11-13-2007 02:05 PM
Open browswer window behavior question worldly1 Web Design Lobby 1 07-13-2007 12:57 AM
Open all links in new window Jazzee Coding Forum 18 12-17-2003 03:58 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 03:52 AM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC