Javascript Simplest Detect Page Refresh Code
Simplest Reliable Way to Detect Page Refresh in Javascript via Function isPageRefresh()
Home
Short:
Try refreshing this page and then going to a different page and come back
function isPageRefresh() { if (!window.performance || !window.performance.getEntriesByType) { return false; } const entries = window.performance.getEntriesByType("navigation"); if (entries.length === 0) { return false; } const type = entries[0].type; // Check if the type is 'reload' return type === "reload"; }
source code home