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

JavaScript capture window closing event_javascript tips

WBOY
Release: 2016-05-16 18:49:08
Original
1110 people have browsed it
1. Use javascript to redefine the window.onbeforeunload() event
Just define a function in javascript
function window.onbeforeunload() { alert("Close the window")}
The alert() event will be executed before closing the window. You can also let the user decide whether to close the window
function window.onbeforeunload() {
if (event.clientX>document.body.clientWidth && event.clientYwindow.event.returnValue="Are you sure you want to exit this page?";
}
2. Use the onUnload method
in the body tag Add the onUnload event
body onUnload="myClose()"
Then define the myClose() method in javascript
But the onUnload method is executed after closing the window, not before closing the window. If you want to To make a judgment before closing the window, please use the first method

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