I am trying to trigger event when user hit the back button on my web page and then show an alert window. I've tried all the possible solutions, but each works only after user interacts with my web page, for example: .onbeforeunload
, or
if (window.history && window.history.pushState) {
window.history.pushState('forward', null, './#');
$(window).on('popstate', function () {
alert('Are you sure?');
window.history.pushState('forward', null, './#');
});
}
I want to ask you, if is it possible, to show alert window without any previous interaction, especially on mobile browsers?