Results 1 to 4 of 4

Thread: Can't Close Tab

  1. #1

    Default Can't Close Tab

    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.

  2. #2
    Web Consultant
    Array
    Join Date
    Aug 2008
    Location
    Las Vegas
    Posts
    9,837
    Blog Entries
    1

    Default

    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.

  3. #3

    Default

    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.
    "We are what we repeatedly do. Excellence, then, is not an act, but a habit" - Aristotle. I've just started a SHTF Prepper blog.

  4. #4

    Default

    Thanks, maidanez, I appreciate the explanation.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •