anytime I'm trying to reference my global variable i get an Uncaught TypeError: undefined is not a function error and nothing happens. I'm probably missing something obvious since I'm new to javascript.
I've simplified the code below so that you can give it a look. All help is much appreciated.
var popup;
function first(){
popup = window.open(...); //opens a popup
popup.moveTo(10,10) //moves the window
second();
}
function second(){
.
.
.
//does an XMLHttpRequest and when it's done (simplified) it tries to close the window
xmlHttp.onreadystatechange = function(){
popup.close();
}
}
Whenever popup.close() is fired I get the error above. Am I missing something really obvious here?
For future problems as this, here is a solution:
instead of popup.close();
var win = window.open("","popup");//open a new window with the same name as before
win.close();
By doing so it will reference the same window object and will be able to close it.
closein thepopobjectpopupinsidefirstand passing it tosecondas argument.