The question is pretty much in title.
Is there a way in Javascript to determine whether the page has been refreshed by user or loaded after redirecting from other website?
The question is pretty much in title.
Is there a way in Javascript to determine whether the page has been refreshed by user or loaded after redirecting from other website?
Share Improve this question edited Nov 11, 2016 at 17:27 payam_sbr 1,4261 gold badge16 silver badges25 bronze badges asked Nov 11, 2016 at 16:50 francescafrancesca 5973 gold badges10 silver badges22 bronze badges 3-
3
Try checking
document.referrer
. – user5734311 Commented Nov 11, 2016 at 16:52 - You can try by checking request referer. It tells you who referred you to this page. If the referrer is same - Refresh else redirect – Vatsal Commented Nov 11, 2016 at 16:53
- that's not accurate if you try refreshing this page and use document.referrer it will tell you its stackoverflow. not the plete url – Ryad Boubaker Commented Nov 11, 2016 at 16:54
2 Answers
Reset to default 5performance.navigation.type
will tell you if the page was reloaded, and some more info. Check out the docs here
Just to give a straight answer, as the answer above says you should
console.log(window.performance.navigation.type)
to see if the page was reloaded or redirected. 1 = reloaded and 0 = redirected.