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

[913 byte] By [Surekha_Venugopal] at [2007-9-30 2:29:21]
# 1
http://javascript.internet.com/page-details/close-window.htmlThe webpage didn't prompt to close, and they don't use self.opener = this;
rkippen at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks for the response. But window.close(); will also prompt a confirmation box. It is same as self.close() / top.close().
Surekha_Venugopal at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 3
try finding helping on a Javascript forum. I guess lots more knowladge about Javascript is gathered there.
pgeuens at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 4

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.

rkippen at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 5
actually, now it started prompting... not sure why it didn't before.
rkippen at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 6
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. :-|
Surekha_Venugopal at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 7
Did you try window.self.close(); ?
rkippen at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 8
looks like it might not be possible http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20673314.html
rkippen at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 9

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

Surekha_Venugopal at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 10
Wow! Finally an answer! This is great... it actually works!Thanks Surekha_Venugopal!=)
lee_the_flee at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 11
Hi,It was really very nice one.It's works exactly what is required good Job...Carry on...........
Nishant_Giri at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 12
> Hi,> It was really very nice one.It's works exactly> exactly what is required good Job...Carry> on...........May I remind that this complete thread is in the wrong forum.
aniseed at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 13
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
hardworker at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 14
Will be interesting to see how this solution (using the close parent window) will be handled in IE7 with the newly added tab features.
Toniez at 2007-6-29 2:14:33 > top of Java-index,Java Essentials,Java Programming...
# 15
> Will be interesting to see how this solution (using> the close parent window) will be handled in IE7 with> the newly added tab features.will be interesting to see what this has to do with java, too
georgemc at 2007-6-30 21:19:14 > top of Java-index,Java Essentials,Java Programming...