Skip to content

Instantly share code, notes, and snippets.

@blubbll
Created March 22, 2019 12:42
Show Gist options
  • Save blubbll/1e575b481d96572c676d499f1ab21bda to your computer and use it in GitHub Desktop.
Save blubbll/1e575b481d96572c676d499f1ab21bda to your computer and use it in GitHub Desktop.
get window navigation type js (https://stackoverflow.com/a/55087265)
setTimeout(function () {
$3.navigationType = function () {
var result;
var p;
if (window.performance.navigation) {
result = window.performance.navigation;
if (result === 255) { result = 4; }
}
if (window.performance.getEntriesByType("navigation")) {
p = window.performance.getEntriesByType("navigation")[0].type;
if (p === 'navigate') { result = 0; }
if (p === 'reload') { result = 1; }
if (p === 'back_forward') { result = 2; }
if (p === 'prerender') { result = 3; }
}
return result;
};
}, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment