2012-05-31

Add a confirm box when user leaves the web page

You can use the following javascript to alert the user when s/he leaves the page.

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

If the user press cancel, user can stay on the same page.

No comments: