Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
How to show alert message when closing a Mobile Browser window?
Posted
Updated 7-Aug-17 10:06am

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.
 
Share this answer
 
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 ?';
});
JavaScript
<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>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900