开发者

how can i get the url from history.go(-2)

开发者 https://www.devze.com 2023-01-21 16:14 出处:网络
I have a question, is it possible to get the url from the history.go(-2)? Assuming i don\'t know that url.

I have a question, is it possible to get the url from the history.go(-2)? Assuming i don't know that url.

edit

I need the url, because I want to 开发者_Go百科check where the visitor was redirected from. there are two cases: 1 facebook, 2 directly on the website. the second step is an automatic user check. the third step is miscoded, but if I go back to step 1. I can bypass the error. with everything working fine. the problem is that I don't know where to redirect (being two forwarders).


It is not, by design, for privacy reasons.


You can in some special circumstances get the previous URL with history.previous (and likewise for .current and .next) but you can't look back arbitrarily and see where I (the visitor) went two or three or ten pages ago. From a website, reliably getting even the most recent page URL (which is sometimes available as the "referer") is never guaranteed.

Thinking about it from your visitor's perspective, this is good. Just because I'm visiting your site now doesn't mean I want you to know about every other page I've ever visited in the same browser window.


No, not in general.

If the URL is on the same hostname as the current page you sort of could, by opening a pop-up window, navigating back 2, then using script in the pop-up to read the opener.location, navigate forward 2, and pass the URL to script in the opener. But it would be an enormous pain and pretty unreliable.

If the URL isn't on the same hostname, you can't at all, for privacy reasons.


I'm not sure if this is possible with your set up, but you could add a GET veriable (ie. page.ext?ref=1) and then store that in a session and output it on whatever page you need. Then, on your facebook page, you could add ?ref=1 to the link. This would allow you to add other site references in the future as well.


It probably isn't possible as history.go() does a URL redirection.

You can get the previous/next URL by doing history.previous/history.next property respectively. This returns you an absolute URL. For current URL, use history.current.

More info on history object.

  • DevGuru.com
  • Exforsys.com
0

精彩评论

暂无评论...
验证码 换一张
取 消