hey I am counting the time spent by user in the page. My problem is how to detect if the page refresh or is open a new tab
if (window.performance) {
console.info("window.performance works fine on this browser");
}
if (performance.navigation.type == 1) {
console.info( "This page is reloaded" );
} else {
console.info( "This page is not reloaded");
}
window.onbeforeunload
and write a function.window.onblur
and write a function.Both these hooks are compatible across all the major browsers Chrome, Firefox, Safari, Edge and IE.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.