开发者

Is it possible to set Request.UrlReferrer in the client side javascript? If so, how?

开发者 https://www.devze.com 2023-03-22 21:06 出处:网络
I have this application that relies extensively on Request.UrlReferrer for handling link clicks and maintaining a page history of where a user has been in the application.

I have this application that relies extensively on Request.UrlReferrer for handling link clicks and maintaining a page history of where a user has been in the application.

The requirements have changed and I now need to navigate in a certain location using <input type="button" /> instead of <a href="mypage.aspx"/>

Currently I'm experimenting with

<input type="button" 
onclick='ShowLoadingScreen();document.write("<a id=\"link\" style=\"display:none;\" href=\"mypage.aspx\">link</a>");document.getElementById("link").click();'>
Do Thing
</input>

but the code is not as clean as I would like and writing to the document blows away my loading screen. If I set innerHTML of something on the page my click ceases to work.

From the Microsoft Documentation

Clients can falsify or choose not to present a Referer header. Therefore, while the UrlReferrer property can be useful for identifying basic trends in Web traffic; you should not use it as part of an authorization scheme to control access to data.

So it is possible to falsify it which would work wonderfully for my purposes. However I do not know how to achieve this.

Is there a way to fake the UrlReferrer using javascript so that I may keep my code to a minimum? Something like

<input ty开发者_C百科pe="button" 
onclick='ShowLoadingScreen(); SetUrlReferrer(); window.location="mypage.aspx";'>
Do Thing
</input>

Unfortunately this does not work.

document.referrer = 'myref.aspx';

Error: Object doesn't support this action


I'm sorry, but i don't think that it will work. This is only possible if you build the http request by hand (even with ajax you will get problems on most browsers)

0

精彩评论

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