onbeforeunload
-
關閉或刷新瀏覽器會觸發此事件
-
示例代碼
window.onbeforeunload = function(ev) { return true; };
popstate
-
示例代碼
window.history.pushState("123", null, document.URL); window.addEventListener("popstate", function() { _this.isMsgShow = true; history.pushState("123", null, document.URL); });
-
當點擊瀏覽器前進或者后退按鈕會觸發此事件
-
基本上不用這個事件,vue 框架可以幫助代替這個事件