tags:

views:

3004

answers:

6

How can I close a browser window without receiving the "Do you want to close this window" prompt"?

The prompt occurs when I use the window.close(); command.

Derek

A: 

The best solution I have found is:

this.focus(); self.opener=this; self.close();

Derek
+2  A: 

From here:

<a href="javascript:window.opener='x';window.close();">Close</a>

You need to set window.opener to something, otherswise it complains.

Harley
this does not work
Ghommey
A: 

The browser is complaining because you're using JavaScript to close a window that wasn't opened with JavaScript, i.e. window.open('foo.html');.

Bill Ayakatubby
+2  A: 

window.opener=window; window.close();

+5  A: 

My friend.. there is a way but Hack does not begin to describe it. You have to basically exploit a bug in IE 6 & 7.

Works every time!

Instead of calling window.close() redirect to another page.

Opening Page:

alert("No whammies!");
    window.open("closer.htm", '_self');

Redirect to another page. This fools IE into letting you close the browser on this page.

Closing Page:

<script type="text/javascript">

    window.close();

Awesome huh?!

-Nick

Nick
This still works in IE 8 too..
Nick
Sweet, thanks very much.
Moose Factory
You are the awesomest! :PI'll give You 10 upvotes for that ;)
naugtur
A: 

window.open('', '_self', ''); window.close(); This works for me.

froggy