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

Viewed 372137

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(); function.

18 Answers

In the body tag:

<body onload="window.open('', '_self', '');">

To close the window:

<a href="javascript:window.close();">

Tested on Safari 4.0.5, FF for Mac 3.6, IE 8.0, and FF for Windows 3.5

From here:

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

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

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

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');.

The best solution I have found is:

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