问题
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);
}
回答1:
if ('onpagehide' in window) {
//if(window.onpagehide || window.onpagehide === null){
window.addEventListener('pagehide', exitFunction, false);
} else {
window.addEventListener('unload', exitFunction, false);
}
来源:https://stackoverflow.com/questions/6906146/how-to-detect-browser-support-for-pageshow-and-pagehide