Home > Web Front-end > JS Tutorial > body text

How to close browser events in javascript

coldplay.xixi
Release: 2021-04-19 15:15:13
Original
4903 people have browsed it

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;
};
Copy after login

2, popstate

Sample code

window.history.pushState("123", null, document.URL);
window.addEventListener("popstate", function() {
    _this.isMsgShow = true;
    history.pushState("123", null, document.URL);
});
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template