PDA

View Full Version : Can't Close Tab



billbenson
11-24-2018, 05:36 PM
Out of curiosity, I just clicked on an ad by mistake and got a popup of "do I really want to close window" when I tried to close the tab. I clicked on the popup and the tab did close. I just wondered what the site is doing in code to do this, and what is the best way in windows / chrome to close the tab when this happens? I don't like clicking on popup's as you never know what they are going to do.

Harold Mansfield
11-25-2018, 11:37 AM
The best answer is to stop the pop ups before they can happen and stop tracking before it happens.
For Chrome I use
Ad Blocker Plus
Privacy badger
HTTPS Everywhere.

maidanez
12-18-2018, 06:21 AM
Since you asked what site is doing in code to do this. Firstly the site is allowed to open a popup bypassing your default browser popup blockers because you actively clicked something on the page. Your browser assumes you intended to do the action. The new tab then install a beforeunload handler. Quoting MDN:

"The beforeunload event is fired when the window, the document and its resources are about to be unloaded. The document is still visible and the event is still cancelable at this point."

It's designed for web applications and web forms where you may have entered a large amount of data and will be likely to lose it. You used to be able to put your own message in the dialog box, but now it's set at a default "you may lose changes" type message. It's very useful when used for the correct purposes. Many many years ago you used to be able to manipulate the browser from the handler, so people made joke pages that couldn't be closed. These days pretty much anything but the simplest code will get ignored.

billbenson
12-18-2018, 03:22 PM
Thanks, maidanez, I appreciate the explanation.