I have a problem. There are two functions I assigned to two buttons, each would pop up up if click. At all times, there will be only one pop up at a time(or so I desire). This is what I have done so far:
var ADD_TESTER_POPUP = null;
var DELETE_TESTER_POPUP = null;
// user clicks on Add Tester
function openAddNewTesterWindow(width, height)
{
//if no windows are open
if((ADD_TESTER_POPUP===null || ADD_TESTER_POPUP.closed) &&
(DELETE_TESTER_POPUP===null || DELETE_TESTER_POPUP.closed))
{
var left = (screen.width/2)-(width/2);
var top = (screen.height/3)-(height/3);
ADD_TESTER_POPUP = window.open("addNewTesterWindow.html", "", "scrollbars=1,
resizable=1, width="+width+", height="+height+", top="+top+", left="+left);
}
else
{
//error occurs at this if statement line only
//if add tester is already open
if((!ADD_TESTER_POPUP===null || !ADD_TESTER_POPUP.closed) &&
(DELETE_TESTER_POPUP===null || DELETE_TESTER_POPUP.closed))
{
ADD_TESTER_POPUP.focus();
}
//if delete tester is open
else if((ADD_TESTER_POPUP===null || ADD_TESTER_POPUP.closed) &&
(!DELETE_TESTER_POPUP===null || !DELETE_TESTER_POPUP.closed))
{
alert("Please close Delete Tester Window before adding tester.");
DELETE_TESTER_POPUP.focus();
}
}
} // openAddnNewTesterWindow(width, height)
// user clicks on Delete Tester
function openDeleteTesterWindow(width, height)
{
//if no windows are open
if ((ADD_TESTER_POPUP===null || ADD_TESTER_POPUP.closed) &&
(DELETE_TESTER_POPUP===null || DELETE_TESTER_POPUP.closed))
{
var left = (screen.width/2)-(width/2);
var top = (screen.height/3)-(height/3);
DELETE_TESTER_POPUP = window.open("deleteTesterWindow.html", "", "scrollbars=1,
resizable=1, width="+width+", height="+height+", top="+top+", left="+left);
}
else
{
//if delete tester is already open
if((ADD_TESTER_POPUP===null || ADD_TESTER_POPUP.closed) &&
(!DELETE_TESTER_POPUP===null || !DELETE_TESTER_POPUP.closed))
{
DELETE_TESTER_POPUP.focus();
}
//if add tester is already open
else if((!ADD_TESTER_POPUP===null || !ADD_TESTER_POPUP.closed) &&
(DELETE_TESTER_POPUP===null || DELETE_TESTER_POPUP.closed))
{
alert("Please close Add Tester Window before deleting tester.");
ADD_TESTER_POPUP.focus();
}
}
} // openDeleteTesterWindow(width, height)
When Add New Tester window is opened first, if user tries to click on Delete Tester button it would alert the user. When Delete Tester window is opened, if user tries to click on Add New Tester button it would alert the user.
However if I opened the Delete Tester Window first(refreshed/clean page), and I click on the Add New Tester button, an error would occur indicating Uncaught TypeError: Cannot read property 'closed' of null(This is using Chrome's debugger tool). I have indicated at the code where the error occurs, in the first function. Any help on this?
Found the answer. It was a logical error, had to check whether a pop up is opened first or not. Just a simple switch between the
ifandelse ifin theelsestatement solves it.