onbeforeunload - 我可以得到调用的原因吗?我想确定一个重定向

时间:2014-05-08 13:38:07

标签: javascript angularjs redirect onbeforeunload

我需要弹出一个'验证保存'使用onbeforeunload事件的消息(当用户关闭窗口或点击“离开我的Angular应用程序页面”的链接时)。

这很有效,但我意识到当我获得302重定向时,事件也会发生 现在我知道我在卸载页面之前已经知道了,但是当我被重定向时,我不想让它运行。

如何检测事件的重定向?

$window.onbeforeunload = function (event) {
       // how can I identify if this event was invoked due to a redirect?    
       return "If you leave the page now your changes won't be saved.";
}

0 个答案:

没有答案
相关问题