Is there any way if we can check if the browser's refresh button is clicked, F5 is pressed or reload is clicked in Vue?
Any inputs or suggestions is appreciated.
Is there any way if we can check if the browser's refresh button is clicked, F5 is pressed or reload is clicked in Vue?
Any inputs or suggestions is appreciated.
Update: As noted by @Paolo, performance.navigation
is deprecated, use PerformanceNavigationTiming instead.
The Navigation Timing API, specifically PerformanceNavigation.type, will tell you how the page was accessed.
0 - TYPE_NAVIGATE
The page was accessed by following a link, a bookmark, a form submission, a script, or typing the URL in the address bar.
1 - TYPE_RELOAD
The page was accessed by clicking the Reload button or via the Location.reload() method.
2 - TYPE_BACK_FORWARD
The page was accessed by navigating into the history.
255 - TYPE_RESERVED
Any other way.
Example Usage:
// does the browser support the Navigation Timing API?
if (window.performance) {
console.info("window.performance is supported");
}
// do something based on the navigation type...
switch(performance.navigation.type) {
case 0:
console.info("TYPE_NAVIGATE");
break;
case 1:
console.info("TYPE_RELOAD");
break;
case 2:
console.info("TYPE_BACK_FORWARD");
break;
case 255:
console.info("255");
break;
}