Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 312
Derek Avatar asked Sep 11 '08 22:09

Derek


People also ask

What does it mean to close your browser window?

Generally speaking, it is a good practice to close your web browser after accessing any website that requires a username and password. It is especially important when you are on a public computer. It ensures that the next person to use that computer won't be surfing the net as you.

Can we disable browser close button?

No, you can't disable the close button on any web site. This would be a major security concern.


2 Answers

window.open('', '_self', ''); window.close(); 

This works for me.

like image 72
Arabam Avatar answered Oct 07 '22 12:10

Arabam


Scripts are not allowed to close a window that a user opened. This is considered a security risk. Though it isn't in any standard, all browser vendors follow this (Mozilla docs). If this happens in some browsers, it's a security bug that (ideally) gets patched very quickly.

None of the hacks in the answers on this question work any longer, and if someone would come up with another dirty hack, eventually it will stop working as well.

I suggest you don't waste energy fighting this and embrace the method that the browser so helpfully gives you — ask the user before you seemingly crash their page.

like image 21
rvighne Avatar answered Oct 07 '22 11:10

rvighne