简体   繁体   中英

history.back only if referrer same website

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 eg google.com. Couldn't find a working solution yet.

Is this 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. AC# example:

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

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

</script>

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