iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack (1) Thread Tools
Old July 29th, 2006, 03:51 PM   1 links from elsewhere to this Post. Click to view. #1
New Member
 

Join Date: Jul 2006
Location: London
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 javascript is on a distinguished road
Question Need to open ALL links in new window

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
javascript is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old July 30th, 2006, 06:45 PM   #2
New Member
 

Join Date: Jul 2006
Location: Earth
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 jtek is on a distinguished road
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; July 30th, 2006 at 06:53 PM..
jtek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old July 31st, 2006, 09:44 AM   #3
New Member
 

Join Date: Jul 2006
Location: London
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 javascript is on a distinguished road
Re: Need to open ALL links in new window

Quote:
Originally Posted by jtek View Post
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');
}
}
Nope this code doesn't work.
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
javascript is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old July 31st, 2006, 01:19 PM   #4
New Member
 

Join Date: Jul 2006
Location: Earth
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 jtek is on a distinguished road
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.
Code:
//test.htm
<html>
<head>
<script>
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>
</head>
<body>
<iframe src="test2.htm" width="200" height="100"></iframe>
</body>
</html>
Code:
//test2.htm
<html>
<head>
</head>
<body>
<a href="test.htm">one</a><br><br>
<a href="test.htm">two</a><br><br>
<a href="test.htm">three</a>
</body>
</html>

Last edited by jtek; July 31st, 2006 at 01:21 PM..
jtek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 4th, 2006, 03:46 PM   #5
New Member
 

Join Date: Jul 2006
Location: London
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 javascript is on a distinguished road
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
javascript is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
open , links , window


LinkBacks (?)
LinkBack to this Thread: http://webforumz.com/javascript/7767-need-to-open-all-links-in.htm
Posted By For Type Date
ulvund's Bookmarks on Delicious This thread Refback August 9th, 2008 01:28 PM

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

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
how can have iframe links to open in a new window? onSPOT HTML, XHTML and CSS 1 March 10th, 2008 05:43 AM
Why do links in a frame open a new window? SpecialBrew HTML, XHTML and CSS 8 January 25th, 2008 05:50 AM
Change open in new window to open in same window nsr500rossi JavaScript 2 January 18th, 2008 11:13 AM
[SOLVED] open new window from main window AdRock Other Languages 1 November 1st, 2007 12:45 AM
Need JavaScript for html links should open in a new window in the first time, after.. jayaramgussy JavaScript 0 June 19th, 2007 06:00 AM


Search Engine Optimization by vBSEO 3.2.0 RC8