Execute a script when a user navigates away from a page in HTML?



When the user navigates from a page, the onpagehide attribute triggers. The navigation occurs when a user clicks a link, closes the browser tab, submits a form, etc.

To execute it, try −

<p onpagehide = "myScript">

You can also use,

object.onpagehide = function(){script};
Updated on: 2020-03-03T07:37:07+05:30

236 Views

Kickstart Your Career

Get certified by completing the course

Get Started