Click here to Skip to main content
14,267,453 members
Rate this:
Please Sign up or sign in to vote.
How to show alert message when closing a Mobile Browser window?
Posted
Updated 7-Aug-17 10:06am
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi,


JQuery :http://jquery.com/[^]

Jquery Detect unload or close : http://api.jquery.com/unload/[^]


Quote:
The exact handling of the unload event has varied from version to version of browsers. For example, some versions of Firefox trigger the event when a link is followed, but not when the window is closed. In practical usage, behavior should be tested on all supported browsers, and contrasted with the proprietary beforeunload event.
   
Comments
JagdevMishra 26-Sep-14 7:21am
   
Yes, but it not working for mobile browser.
Suvabrata Roy 26-Sep-14 8:49am
   
Try this :

$(window).on('beforeunload ',function() {
return 'Are you sure ?';
});
Rate this:
Please Sign up or sign in to vote.

Solution 2

<script>
window.onbeforeunload = function (e) {
    e = e || window.event;

    // For IE and Firefox prior to version 4
    if (e) {
        e.returnValue = 'Sure?';
    }

    // For Safari
    return 'Sure?';
};
</script>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100