A Working Exit Popup

Demonstration can be seen here.
Sample code can be downloaded here.

Full Example Code

<body onunload="SomeFunction()">

iFrame Example

<script type="text/javascript">
     window.onbeforeunload = function() { return "Are you sure you want to leave?"; }
</script>

9 comments

  1. Brandon says:

    Thank you for your post on A Working Exit Popup. This is exactly what I was looking for.

  2. artur says:

    hi,

    is there a way to bypass the Alert Msg window ” are u sure u want to …” and just show the Fancybox pop up instead?

    seems like its an unnecessary extra step to take.

    *time sensitive issue*

    thanks!

    artur

  3. kbeezie says:

    The popup “are you sure” is there as a security measure by the browser, currently without finding an exploit existing in a browser (which no doubt would get patched quickly) there is no way to bypass that dialog.

  4. mike sherman says:

    Great script – What would the script be to launch the exit pop that contains a site on another server, ie yahoo.com

  5. dubek says:

    Just what i needed! very good article!
    Wanted to know if its possible to change the alert box buttons text??
    I want to change the ‘Stay on Page’ to something else.
    thanks!

  6. Josh says:

    Fantastic post, but here is the challenge – how can you modify this script so it could be placed on every page and ONLY trigger when they are closing the browser or leaving your DOMAIN? I want to prompt for feedback from a small % of all users who abandon to learn more and need a way to only pop if they do, in fact, abandon.

  7. kbeezie says:

    That is why there was the anchor trigger, it can be adapted to for other forms of triggers to turn off the popup since there’s no way for javascript to know closing browser vs link taking them away from the page.

    And as far as ‘every page’ goes, you’ll likely just have to include the script via php or whatever server-sided language you use on every page.

  8. Joshua says:

    Is it possible to tell javascript:
    “if the visitor is going to these pages, don’t use the popup” ??

    Thanks, nice post!

  9. kbeezie says:

    If you noticed the anchor event does an UnPopIt() , likewise you would just apply that change to events where needed.