Created
October 19, 2018 06:08
-
-
Save liuwenzhuang/a0acd9b2abd7ac6c399421950f3853bb to your computer and use it in GitHub Desktop.
离开页面前的监听事件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener("beforeunload", function (event) { | |
if (!checkSomething()) { // 假设已存在此方法 | |
// 标准 | |
event.preventDefault(); | |
// Chrome需要 | |
event.returnValue = ''; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment