最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

http redirect - Javascript Determine if page was refreshed or redirected from another page? - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 5

performance.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.

发布评论

评论列表(0)

  1. 暂无评论