I can't understand what is the reason that makes these 2 scripts written in javascript behave in different ways.
Script 1
var w;
function f1() {
w = window.open("pg1.html","wind","left=0,top=0,width=480,height=480");
}
function f2() {
w.close();
}
function f3() {
w.open("pg1.html","wind","left=0,top=0,width=480,height=480");
}
Script 2
function f() {
var w = window.open("pg1.html","wind","left=0,top=0,width=480,height=480");
w.close();
w.open("pg1.html","wind","left=0,top=0,width=480,height=480");
}
In case of script 1, if i execute function f1()
, then f2()
(as you can see f1()
creates new window object and assigns the reference to that object to variable w
, f2()
closes window object created by f1()
) and try to execute function f3()
afterwards, closed popup window (w
) doesn't open and in Firefox 19 I get error:
Error: NS_ERROR_NOT_AVAILABLE: Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMJSWindow.open],
In IE8 I get error:
The object invoked has disconnected from its clients,
In Chrome 25 I get no errors.
Execution of script 2 (function f()
that creates new window object, assigns the reference to that object to variable w
, closes created window and then tries to reopen it) doesn't cause any errors in browsers, but in Firefox f()
makes closed popup window reopen, while in IE and Chrome the popup window (w
) remains closed.
Could You please try these two scripts and help me to understand the reason of such strange behavior?
Firstly, I hope you are not up to doing what the question implies. Then, I ran the following in firebug console and got different references for sample 2 and 3:
console.log('sample 1', w); // undefined
f1();
console.log('sample 2', w); // Window about:blank
f2();
console.log('sample 3', w); // Window
It appears w.close();
destroys the reference to the new window.
User contributions licensed under CC BY-SA 3.0