Javascript method to close browser events: 1. Use the onbeforeunload method. Closing or refreshing the browser will trigger this event; 2. Use the popstate method, the code is [history.pushState("123", null, document .UR】.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, DELL G3 computer.
javascript is turned off Browser event methods:
1, onbeforeunload
Closing or refreshing the browser will trigger this event
Sample code
window.onbeforeunload = function(ev) { return true; };
2, popstate
Sample code
window.history.pushState("123", null, document.URL); window.addEventListener("popstate", function() { _this.isMsgShow = true; history.pushState("123", null, document.URL); });
Related free learning recommendations: javascript video tutorial
The above is the detailed content of How to close browser events in javascript. For more information, please follow other related articles on the PHP Chinese website!