...

View Full Version : Get popups to open with target



chris_denman
06-24-2006, 11:08 AM
Hi!

I know how to make a new window appear by using...


<script language="javascript">function newwin() { window.open("http://www.foo.com","newwin","width=250,height=300") } </script>
<a href="javascript:newwin()">New Window</a>

But in this specific instance, I want to do it using:


<a href="http://www.foo.com" target="newwin">

I remember reading that this was possible but I can't work out the script which goes in the HEAD for it!

Thanks so much for anyone who can help :)

Chris

_Aerospace_Eng_
06-24-2006, 05:36 PM
Something like this?

<html>
<head>
<script type="text/javascript">
function newwin(url)
{
var thewin = window.open(url,'thewin','width=250,height=300')
if(thewin) thewin.focus();
}
function setWin()
{
var thelinks = document.getElementsByTagName('a');
for(var i = 0; i < thelinks.length; i++)
{
if(thelinks[i].getAttribute('target') == 'newwin')
{
thelinks[i].onclick = function()
{
newwin(this.href);
return false;
}
}
}
}
window.onload = setWin;
</script>
</head>
<body>
<a href="http://www.google.com" target="newwin">google</a><br>
<a href="http://www.yahoo.com" target="newwin">yahoo</a><br>
<a href="http://www.codingforums.com">codingforums</a>
</body>
</html>

chris_denman
06-25-2006, 01:57 PM
You're a genius... thanks so much!!:) :)

Chris



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum