PDA

View Full Version : Close window before opening it


souldrifter02
08-08-2003, 04:48 PM
I have a function to open a new window as below:

function map(str){
mapWindow=window.open("", "newwin", "height=504,width=700,toolbar=no,scrollbars=no,menubar=no");
mapWindow.document.write(" <title>Interactive Map</title><frameset cols='500,200' framespacing='0' border='0' frameborder='0'> ");
mapWindow.document.write(" <frame name='map' src='../map/map.html?"+str+"' scrolling='auto' noresize> ");
mapWindow.document.write(" <frame name='menu' src='../map/menu.html?"+str+"' scrolling='auto' noresize> ");
mapWindow.document.write(" <noframes><body><p>This page uses frames, but your browser doesn't support them.</p> </body></noframes> ");
mapWindow.document.write(" </frameset> ")
}

It creates a frameset and loads the files I want based on what I call str in the function. It works great!
EXCEPT.... if the window is already open, it ignores the click.

I use this script to open a map to show specific things in the city- like the parks. So if I'm on Park A page and I click show Map- the map shows up- then if I click off the map (not closing the window) and then got to Park B and click Show Map- nothing happens.

How can I check to see if the mapWindow exists and if it does, close it before re-opening it again.

I keep getting the error message that mapWindow is undefined when I try this:

if(mapWindow){
mapWindow.close
}

What am I missing?

Jon Hanlon
08-08-2003, 05:26 PM
You need the brackets after the .close

if(window.mapWindow && !mapWindow.closed()){
mapWindow.close()
}