IE:当按下后退按钮时,删除onbeforeunload事件

时间:2018-11-16 15:11:51

标签: internet-explorer back onbeforeunload

正如标题所述,我想在Internet Explorer上按“后退”按钮时删除“ beforeunload”侦听器。到目前为止,这是我所做的(这是一个AngularJS应用程序):

 window.addEventListener('popstate', function (e) {
  window.onbeforeunload = null;
  e.preventDefault();
  window.location.href = window.location.origin + window.location.pathname;
});
if ($rootScope.isIE) {
  window.addEventListener('hashchange', function (e) {
    window.onbeforeunload = null;
    e.preventDefault();
    window.location.href = window.location.origin + window.location.pathname;
  });
}

它在其他浏览器中也可以正常工作,但是当按下后退按钮时,我仍然收到确认消息。不幸的是,对于应用程序的工作方式,单击“停留在此页面上”会破坏应用程序。

0 个答案:

没有答案
相关问题