Created
November 1, 2017 17:47
-
-
Save conorgil/da0f931c23d35eede0033e261bc7e7e6 to your computer and use it in GitHub Desktop.
Short demo using window.performance.navigation to determine whether page was reloaded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigation | |
// https://blog.chromium.org/2017/09/chrome-62-beta-network-quality.html | |
// https://stackoverflow.com/questions/46226144/window-performance-navigation-type-works-in-ie-and-firefox-but-not-in-chrome | |
// This demo works as of 2017-11-01 | |
const TYPE_RELOAD = 1; | |
function isReloadedPage() { | |
return performance.navigation.type === TYPE_RELOAD; | |
} | |
function main() { | |
if (!isReloadedPage()) { | |
console.info('This page WAS NOT reloaded.'); | |
} else { | |
console.info('This page WAS reloaded.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment