Javascript loses reference to window object.
843842May 29 2008 — edited Jun 1 2008Hi, I think this is a servlet issue but I'm not sure. I am following the standard javascript instructions on opening and referencing a new browser window. The intent is to use a global variable hold the reference to the new window so that when the main window is closed, javascript can automatically close the new window as well. Unfortunately after the new window is opened the reference is lost? Here is what I'm doing:
There are two buttons on a JSP page, thats all. One is open, the other is close. In the 'Open' button I have the onClick event pointed at the javascript openWin() function. In the 'Close' button I have the onClick event pointed at the javascript closeWin() function.
The javascript global variable and functions are simply defined as:
var newWin;
function openWin() {
newWin = window.open("", "");
}
function closeWin() {
newWin.close();
}
When I click the 'Open' button the blank new page opens. I then click on the original page tab in the browser to bring to the front and click the 'Close' button. This results in the following error message:
'newWin' is null or not an object.
Why am I losing reference and what can I do about it?
Your assistance is greatly appreciated.
Don