简体   繁体   English

当我使用 location.href 时,如何获取上一页 url?

[英]How can I get previous page url when i used location.href?

I have used location.href to redirect next page, but now i want to back to this page, how can I do?我已经使用 location.href 重定向下一页,但现在我想回到这个页面,我该怎么办? in my case, i cannot use Request.UrlReferrer.PathAndQuery, so any suggestion?就我而言,我不能使用 Request.UrlReferrer.PathAndQuery,所以有什么建议吗?

Since you are using location.href to change the URL, your browser is going to kick off a new request/response cycle.由于您使用 location.href 更改 URL,您的浏览器将启动新的请求/响应周期。 Thus to your server, there is no referrer - this is a whole new request.因此对于您的服务器,没有引荐来源网址 - 这是一个全新的请求。

The most direct approach to solve your problem would be to add a referrer-url parameter to your new URL, which you can then pick up on the server side.解决您的问题的最直接方法是将referrer-url 参数添加到您的新URL,然后您可以在服务器端获取该参数。

eg: control.location.href = "newpage.aspx?referrer-url=thispage.aspx";例如:control.location.href = "newpage.aspx?referrer-url=thispage.aspx";

and on the server: string referrerUrl = Request["referrer-url"];在服务器上:string referrerUrl = Request["referrer-url"];

If the previous URL is one that you own/can predict (eg the user came from page A or page B), you could use a trick like this one: http://www.merchantos.com/blog/makebeta/tools/spyjax如果之前的 URL 是您拥有/可以预测的(例如,用户来自页面 A 或页面 B),您可以使用这样的技巧: http://www.merchantos.com/blog/makebeta/tools/间谍贾克斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM