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