Reputation: 660
Is there any way onbeforeunload event works, when we close any tab in android browser.
It is working fine in desktop browsers.
Basically in android browser i need "Leave this page" or "stay on this page" pop up in all devices.
Or Is it possible or not ??
Upvotes: 1
Views: 1159
Reputation: 141
I had same issue and found solution, Below code is working for me, I thought I should share solution which works for me. I hope it would help other.
$(document).ready(function()
{ $(window).bind("beforeunload", function() {
return confirm("Do you really want to close?");
});
});
Upvotes: 1
Reputation: 1275
Some browsers don't support onbeforeunload
, instead opting for onunload
. This should work on desktop and mobile:
window.onunload = window.onbeforeunload = function(e) {
return confirm("Are you sure you want to leave this page?");
});
Upvotes: 0