Close parent window using javascript
I am using the following code to open a URL from an HTML file and to close the parent window.
<HTML>
<SCRIPT LANGUAGE="JavaScript">
function foo() {
window.open("http://www.google.com","new_window","status=no,toolbar=no,location=no,menu=no,width=600,height=400");
}
function closewindow() {
self.opener = this;
self.close();
}
</SCRIPT>
<BODY onLoad="JavaScript: foo();closewindow();">
</BODY>
</HTML>
In the above code, "self.opener = this;" is used to avoid the warning message that confirms closing of a window. But because of that Internet Explorer is getting crashed where as netscape works fine.
Please throw some light to overcome this problem or
Is there any other statement which can be used instead of this?
Thanks in advance,
Surekha_Venugopal
Is that in Netscape or Internet Explorer? If that is only the case for Netscape, then you can do a
if (checkBrowser == Netscape)
self.close()
else InternetExplorer
window.close()
When I visit that webpage and click close, it doesn't prompt me to close, it just does.
I think the problem is not with the statement, self.opener = this;Because the code is working as expected (without IE crashing) in some other M/Cs. Even in my M/C, if one IE window is already opened, it is working fine. Not getting what is to be done. :-|
Hi All,
I could avoid the crashing of IE by giving focus to the child window in my code. Now the script works fine. :-)
See the code below.
<HTML>
<SCRIPT LANGUAGE="JavaScript">
function foo() {
window.open("http://www.google.com","new_window","status=no,toolbar=no,location=no,menu=no,width=600,height=400");
this.focus();
}
function closewindow() {
self.opener = this;
self.close();
}
</SCRIPT>
<BODY onLoad="JavaScript: foo();closewindow();">
</BODY>
</HTML>
Hope this information will be useful.
Thanks,
Surekha_Venugopal
hi all,i used the above two codes to open a new window and to close parent window, in IE, but it doesn't works there is no effect of this code, simply it closes the parent window, can any body help me pls