This is a discussion on "Need to open ALL links in new window" within the JavaScript Forum section. This forum, and the thread "Need to open ALL links in new window are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Need to open ALL links in new window
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Hi,
I need a javascript code to put in a small page so that ALL of the links there are opened in a new window. This page will be embeddded in an iframe as it is from another host using php. So all i need to do is add the javascript code to that page. If anyone knows please tell me. P.s I don't want those ones which open new links from other host's (external sites). I need the one to open all the links. Thanks |
|
|
|
#2
|
|||
|
|||
|
Re: Need to open ALL links in new window
document.onload = function() {
var frame = parent.frames[0].document; var links = frame.getElementsByTagName('a'); for (var i=0; i<links.length; ++i) { links[i].setAttribute('target','_blank'); } } Last edited by jtek; Jul 30th, 2006 at 21:53. |
|
#3
|
|||
|
|||
|
Re: Need to open ALL links in new window
Quote:
I'm sure there is a solution to this problem. Here is the javascript code i put in: <SCRIPT language="JavaScript"> document.onload = function() { var frame = parent.frames[0].document; var links = frame.getElementsByTagName('a'); for (var i=0; i<links.length; ++i) { links[i].setAttribute('target','_blank'); } } </SCRIPT> is this correct. If anyone knows, pls reply. Thanks anyway jtek |
|
#4
|
|||
|
|||
|
Re: Need to open ALL links in new window
Sorry for the previous post. I should have tested the code first. It turns out that document.onload needs to be changed to just onload. I have posted my test pages below.
Last edited by jtek; Jul 31st, 2006 at 16:21. |
|
#5
|
|||
|
|||
|
Re: Need to open ALL links in new window
thanks for you help but what i want to do is embed the code in the iframe only so that all of it's links open in a new window
|
![]() |
| Tags |
| open, links, window |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how can have iframe links to open in a new window? | onSPOT | Web Page Design | 1 | Mar 10th, 2008 07:43 |
| Why do links in a frame open a new window? | SpecialBrew | Web Page Design | 8 | Jan 25th, 2008 08:50 |
| Change open in new window to open in same window | nsr500rossi | JavaScript Forum | 2 | Jan 18th, 2008 14:13 |
| [SOLVED] open new window from main window | AdRock | Other Programming Languages | 1 | Nov 1st, 2007 02:45 |
| Need JavaScript for html links should open in a new window in the first time, after.. | jayaramgussy | JavaScript Forum | 0 | Jun 19th, 2007 09:00 |