Home  >  Article  >  Web Front-end  >  jquery method to determine when the browser goes back and a message pops up_jquery

jquery method to determine when the browser goes back and a message pops up_jquery

WBOY
WBOYOriginal
2016-05-16 16:39:55993browse

There must be some messages when the browser goes back. Here we use jquery to determine when the browser goes back and pop up a message

jQuery(document).ready(function ($) {
if (window.history && window.history.pushState) {
$(window).on('popstate', function () {
var hashLocation = location.hash;
var hashSplit = hashLocation.split("#!/");
var hashName = hashSplit[1];
if (hashName !== '') {
var hash = window.location.hash;
if (hash === '') {
alert("Back button isn't supported. You are leaving this application on next clicking the back button");
}
}
});
window.history.pushState('forward', null, './#forward');
}
});

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn