js後退按鈕事件觸發

$(document).ready(function(e) { 
            var counter = 0;
            if (window.history && window.history.pushState) {
                             $(window).on('popstate', function () {
                                            window.history.pushState('forward', null, '#');
                                            window.history.forward(1);
                                           alert("不可回退");
                                });
              }

              window.history.pushState('forward', null, '#'); //在IE中必須得有這兩行
              window.history.forward(1);
});
//頁面關閉時調用
$(window).on("unload", function(event){});
//頁面刷新時調用
$(window).on('beforeunload', function(event) {});
//用戶離開當前網頁跳轉到另外一個頁面時觸發
$(window).on('onpagehide', function(event) {});
//用戶退出頁面
$(window).on("onunload", function(event){});
//直接跳轉
window.location.href="b.html";
//返回上一級頁面
window.history.back(-1);
//返回下一級頁面
window.history.go(-1);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章