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?";

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

No comments: