jquery判斷瀏覽器后退時候彈出消息的方法

字號:


    瀏覽器后退時必定會有一些消息,這里使用jquery判斷瀏覽器后退并彈出消息
    view source
    print?01 jQuery(document).ready(function ($) {
    02 if (window.history && window.history.pushState) {
    03 $(window).on('popstate', function () {
    04 var hashLocation = location.hash;
    05 var hashSplit = hashLocation.split("#!/");
    06 var hashName = hashSplit[1];
    07 if (hashName !== '') {
    08 var hash = window.location.hash;
    09 if (hash === '') {
    10 alert("Back button isn't supported. You are leaving this application on next clicking the back button");
    11 }
    12 }
    13 });
    14 window.history.pushState('forward', null, './#forward');
    15 }
    16 });