View Single Post
  #4 (permalink)  
Old Jul 31st, 2006, 16:19
jtek jtek is offline
New Member
Join Date: Jul 2006
Location: Earth
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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: Select all
//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: Select all
//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; Jul 31st, 2006 at 16:21.
Reply With Quote