The onpagehide attribute fires when the user navigates from the page. Navigation occurs when a user clicks a link, closes a browser tab, submits a form, etc.
To execute it, try -
<p onpagehide = "myScript">
You can also use,
object.onpagehide = function(){script};
The above is the detailed content of Execute a script when the user leaves the HTML page?. For more information, please follow other related articles on the PHP Chinese website!