简体   繁体   中英

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? in my case, i cannot use Request.UrlReferrer.PathAndQuery, so any suggestion?

Since you are using location.href to change the URL, your browser is going to kick off a new request/response cycle. 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.

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

and on the server: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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