1. 程式人生 > >Jquery禁止瀏覽器的前進後退

Jquery禁止瀏覽器的前進後退

jQuery(document).ready(function () {
                  if (window.history && window.history.pushState) {
                      $(window).on('popstate', function () {
                /// 當點選瀏覽器的 後退和前進按鈕 時才會被觸發, 
                          window.history.pushState('forward', null, ''); 
                          window.history.forward(1);
                      });
                  }
          //
                  window.history.pushState('forward', null, '');  //在IE中必須得有這兩行
                  window.history.forward(1);
              });