When the button is clicked, check to see if the window is already open using the 'window.closed' property which returns a boolean. If the child window is open, just give it the focus using the function 'focus()' and if it isn't then open a new one.
<html>
<head>
<script>
var wnd = null;
function openit()
{
if(!wnd || wnd.closed)
wnd = window.open("http://www.google.com");
else
wnd.focus();
}
</script>
</head>
<body>
<form>
<input type="button" value="Open" onclick="openit();" />
</form>
</body>
</html>
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
Your code does not run because you ignore the important aspects of the code posted by me. You have a global variable called 'name' and at the same time have a local variable 'name'. Because of this the local one hides the global one. Change the name of the function variable to something else than 'name'.
The second mistake you make is of not assigning the reference of the newly opened window to the variable 'name'. See my previous example for more info and post your code if it still doesn't work.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
Do something like this:
<SCRIPT>
var name = null;
function openWindow(url, named)
{
if(!name || name.closed)
{
var windowHeight,windowWidth,windowTop,windowLeft
windowHeight = screen.availHeight;
windowWidth = screen.availWidth;
windowTop = 0;
windowLeft = 0;
var varStore = "";
varStore = varStore + "width=" + windowWidth;
varStore = varStore + ",height=" + windowHeight;
varStore = varStore + ",resizable=" + "1";
varStore = varStore + ",scrollbars=" + "0";
varStore = varStore + ",menubar=" + "0";
varStore = varStore + ",toolbar=" + "0";
varStore = varStore + ",directories=" + "0";
varStore = varStore + ",location=" + "0";
varStore = varStore + ",status=" + "1";
varStore = varStore + ",left=" + windowLeft;
varStore = varStore + ",top=" + windowTop;
varStore = varStore + ",ScreenX=" + windowLeft;
varStore = varStore + ",ScreenY=" + windowTop;
name = window.open(url,name,varStore)
}
else
{
name.focus();
}
}
</SCRIPT>
<P align="center"><A href="javascript:openWindow('member_panel.php?page=BO_Home','BO_Home')"><IMG src="http://qlx3.net/images/home.png" alt="Home" width="256" height="217"></A></P>
Oh and BTW, get into the habit of using lowercase alphabets for tag names as we are now in the XHTML era.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
Actually, you should not use html attributes as variable names.
MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
Good point, I missed that one. But considering there are no attributes having the name 'name' in the global namespace (window), there is no harm as such. I for one, don't prefer using such names as my variable names.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
> This still isn't working. Can someone help?
I am sorry to say this, but you have lost the ability to see things as they are. My first post pointed out the mistakes in your code, my second post was a piece of working code and you still come back and say it isn't working?
If you plan on ignoring our posts and advice, do let us know in advance.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
So maybe next time you should place the entire requirement instead of letting us guess whether you want 2 or 3 windows....
<html>
<head>
<script>
var wnd = new Array();
function openit(id)
{
if(!wnd[id] || wnd[id].closed)
wnd[id] = window.open("http://www.google.com");
else
wnd[id].focus();
}
</script>
</head>
<body>
<form>
<input type="button" value="Open1" onclick="openit(0);" /><br/>
<input type="button" value="Open2" onclick="openit(1);" /><br/>
<input type="button" value="Open3" onclick="openit(2);" /><br/>
</form>
</body>
</html>
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
The code you pasted above seems to be working for me. What problems do you experience?
<html>
<head>
<script>
var wnd = new Array();
function openWindow(url,id)
{
if(!wnd[id] || wnd[id].closed)
wnd[id] = window.open(url,"" + id, "width=" + screen.availWidth +
",height=" + screen.availHeight +
",resizable=1,scrollbars=0,menubar=0,toolbar=0,directories=0," +
"location=0,status=1,left=0,top=0,ScreenX=0,ScreenY=0");
else
wnd[id].focus();
}
</script>
</head>
<body>
<input type="button" value="Button1" onclick="openWindow('http://www.google.com', 1);" />
<input type="button" value="Button2" onclick="openWindow('http://www.google.com', 2);" />
<input type="button" value="Button3" onclick="openWindow('http://www.google.com', 3);" />
</body>
</html>
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
Glad I could be of some help.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733