onpagehide event
Definition and usage
The onpagehide event occurs when the user leaves the web page.
There are many ways to leave a page. For example, by clicking a link, refreshing the page, submitting a form, closing the browser window, etc.
The onpagehide event is sometimes used instead of onunload ইভেন্ট, because the onunload event may cause the page not to be cached.
To determine whether the page is loaded directly from the server or cached, you can use the PageTransitionEvent object's Persisted property. If the page is cached by the browser, this property returns true, otherwise it returns false (see more examples below).
Example
Execute JavaScript when the user leaves the web page:
<body onpagehide="myFunction()">
Syntax
In HTML:
<element onpagehide="myScript">
In JavaScript:
object.onpagehide = function(){myScript};
In JavaScript, use the addEventListener() method:
object.addEventListener("pagehide", myScript);
মন্তব্য:Internet Explorer 8 or earlier versions do not support addEventListener() method.
Technical details
Bubble: | Not supported |
---|---|
Cancelable: | Not supported |
Event type: | PageTransitionEvent |
Supported HTML tags: | <body> |
DOM version: | Level 3 Events |
Browser support
Table numbers indicate the first browser version that fully supports this event.
Event | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
onpagehide | সমর্থন | 11.0 | সমর্থন | 5.0 | সমর্থন |
মন্তব্য:ব্রাউজার সেটিংসের পরিবর্তনের কারণে, এই ইভেন্টটি আশা করা ভাবেই কাজ করতে পারে না。