I have this sample code for tracking if back button of the browser is pressed. The code works with IE , Firefox and Safari on computer. When I checked the code with Safari on Ipad, the .confirm dialog is not shown when I press the back button. I've tested with Safari 9 on iOS 9.3. Settings of Safari allows popup.
I have no idea how to make the code works on Ipad Safari. Has anyone same problem?
<html>
<head>
</head>
<body>
<script src="jquery-3.1.0.js"></script>
<script>
jQuery(document).ready(function ($) {
if (window.history && window.history.pushState) {
window.history.pushState(null, null, $(location).attr('href'));
$(window).on('popstate', function () {
$("#lblMessage").html("Onpopstate");
if (!confirm('Browse back?'))
window.history.pushState(null, null, $(location).attr('href'));
else
window.history.back();
});
}
});
</script>
<div id="lblMessage">Status
</div>
</body>
I created a test site here.