Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect browser support for pageShow and pageHide?

How can we do JavaScript object detection for pageShow and pageHide handlers?

if( /* pagehide is supported */ ){
   window.addEventListener('pagehide', exitFunction, false);
}
else{
    window.addEventListener('unload', exitFunction, false);
}
like image 443
epascarello Avatar asked Aug 02 '11 00:08

epascarello


1 Answers

if ('onpagehide' in window) {
   window.addEventListener('pagehide', exitFunction, false);
} else {
   window.addEventListener('unload', exitFunction, false);
}
like image 170
Shaz Avatar answered Sep 20 '22 11:09

Shaz