Please help me before I kill myself.
My goal is this: Close a browser window if it already exists, else do nothing.
When I open a new window using the second function below, the first function will correctly close it. However, if 'openMyWindow' is not called, 'closeMyWindow' raises an error that 'MyWindow' is undefined. If I declare a variable called MyWindow, 'closeMyWindow' doesn't fire correctly.
Any suggestions?
function closeMyWindow() {
if (MyWindow && !MyWindow.closed) {
MyWindow.close();
}
}
function openMyWindow(Page,W,H){
var options = "width="+W+",height="+H;
MyWindow = window.open(Page,'PageWin', options);
MyWindow.focus();
}
My goal is this: Close a browser window if it already exists, else do nothing.
When I open a new window using the second function below, the first function will correctly close it. However, if 'openMyWindow' is not called, 'closeMyWindow' raises an error that 'MyWindow' is undefined. If I declare a variable called MyWindow, 'closeMyWindow' doesn't fire correctly.
Any suggestions?
function closeMyWindow() {
if (MyWindow && !MyWindow.closed) {
MyWindow.close();
}
}
function openMyWindow(Page,W,H){
var options = "width="+W+",height="+H;
MyWindow = window.open(Page,'PageWin', options);
MyWindow.focus();
}