...

View Full Version : Open Window



WandaL
04-29-2004, 05:40 PM
Scenario:
I have a link that when clicked opens a new/2nd window. When I click another link in the 1st window, I would like for that link to open in the 2nd window. The code below is what I'm using but it continues to open new windows when I click a link:

<html>
<head>
<title>Untitled Document</title>
<script language="JavaScript">
<!--

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<a href="javascript:;" onClick="MM_openBrWindow('http://www.espn.com', 'win2','width=450,height=450,resizable,scrollbars')" >ESPN</a>
<br><br>

<a href="javascript:;" onClick="MM_openBrWindow('http://www.cnn.com', 'win2','width=450,height=450,resizable,scrollbars')" >CNN</a>

<body>
</body>
</html>

:confused:

sad69
04-29-2004, 09:07 PM
Well your problem is window.open() opens a new window everytime. What you want to do is something like this:


<script language="JavaScript">
<!--
var win = null;
function MM_openBrWindow(theURL,winName,features) { //v2.0
if(win == null) {
window.open(theURL,winName,features);
}
else {
win.location.href = theURL;
}
}
//-->
</script>


Let me know how that works out for you.

Sadiq.

WandaL
04-29-2004, 09:18 PM
Unfortunately Sadiq, this didn't work either. It is still opening two separate windows.

Can you think of anything else...

sad69
04-29-2004, 09:37 PM
Oops! Missed a small but very important detail:


<script language="JavaScript">
<!--
var win = null;
function MM_openBrWindow(theURL,winName,features) { //v2.0
if(win == null) {
win = window.open(theURL,winName,features);
}
else {
win.location.href = theURL;
}
}
//-->
</script>


That should do the trick.

Sadiq.

WandaL
04-29-2004, 09:41 PM
Thank you Thank you Thank you so very much Sadiq that works but there is one small problem. After the 2nd link is clicked, the window then hides behind any other open window. How can I make the focus the same as the when the 1st link is clicked?

sad69
04-29-2004, 09:45 PM
Sure can:


<script language="JavaScript">
<!--
var win = null;
function MM_openBrWindow(theURL,winName,features) { //v2.0
if(win == null) {
win = window.open(theURL,winName,features);
}
else {
win.location.href = theURL;
win.focus();
}
}
//-->
</script>


That should do the trick for ya.

Pretty quick replies, eh? Kinda funny..

Sadiq.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum