开发者

history.back only if referrer same website

开发者 https://www.devze.com 2023-04-06 04:43 出处:网络
I\'d like to display a back button with the help of history.back, but it should only be displayed if the history page is within the same website / domain. So it should not be displayed if referrer is

I'd like to display a back button with the help of history.back, but it should only be displayed if the history page is within the same website / domain. So it should not be displayed if referrer is e.g. google.com. Couldn't find a working solution yet.

Is t开发者_JAVA百科his possible?

Thx


Referer in javascript is tricky because different browsers support it differently. My preferred method is to catch the referrer using code behind of whatever language I'm using to produce the page and then pass it into the page as a javascript variable. A C# example:

<script language="javascript" type="text/javascript">

    var referer = '<%= Request.UrlReferrer %>';

</script>
0

精彩评论

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

关注公众号