Home>Article>Web Front-end> How to close browser events in javascript

How to close browser events in javascript

coldplay.xixi
coldplay.xixi Original
2021-04-19 15:15:01 4795browse

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】.

How to close browser events in javascript

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn