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

http redirect - Detect if page was redirected or loaded directly(Javascript) - Stack Overflow

programmeradmin4浏览0评论

Currently, I want to display a label on the first page of my site a user visits.

To make it simple, say I only care about page1.html and page2.html.

Is it possible to check if the user was redirected from page1.html to page2.html?(Perhaps with cookies?)

Edit: On page1.html, I set a cookie, which would expire in a minute. On page2.html, I checked for the cookie. Works great!

Currently, I want to display a label on the first page of my site a user visits.

To make it simple, say I only care about page1.html and page2.html.

Is it possible to check if the user was redirected from page1.html to page2.html?(Perhaps with cookies?)

Edit: On page1.html, I set a cookie, which would expire in a minute. On page2.html, I checked for the cookie. Works great!

Share Improve this question edited Jun 1, 2016 at 18:01 mancestr asked Apr 9, 2016 at 20:17 mancestrmancestr 9903 gold badges15 silver badges35 bronze badges 1
  • 1 On the page1.html you set some cookie variable to true and on other pages you set this variable to false. If you want to check if previous page was page1.html you just check this variable. – semanser Commented Apr 9, 2016 at 20:27
Add a ment  | 

1 Answer 1

Reset to default 14

You can use document.referrer.

The value is an empty string if the user navigated to the page directly (not through a link).

  1. For example when user e to URL via bookmaked links click.
  2. User type the full URL in address bar.

Reference https://developer.mozilla/en-US/docs/Web/API/Document/referrer

发布评论

评论列表(0)

  1. 暂无评论