Javascript:document.referrer

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5893684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 18:43:01  来源:igfitidea点击:

Javascript: document.referrer

javascript

提问by jagrti

Say I have included document.referrer()in my website(www.abc.com) and I got redirected to my site from google.com.

假设我已包含document.referrer()在我的网站 ( www.abc.com) 中,并且我从google.com.

Will the above mentioned code help me to get google.com?

上面提到的代码会帮助我得到google.com吗?

回答by Shadow Wizard is Ear For You

The search results in Google are not direct links. For example searching for abcthe first result actual link is: http://www.google.co.uk/url?sa=t&source=web&cd=1&ved=0CC0QFjAA&url=http%3A%2F%2Fabc.go.com%2F&ei=_0nCTeOMFYOVswbY7PyHAQ&usg=AFQjCNHN69w2aXwjgMlF4X6o9W3lKd4uZw

Google 中的搜索结果不是直接链接。例如搜索abc第一个结果的实际链接是: http://www.google.co.uk/url?sa=t&source=web&cd=1&ved=0CC0QFjAA&url=http%3A%2F%2Fabc.go.com%2F&ei=_0nCTeOMFYOVswbY7PyHAQ&usg=AFQjCNHN69w2aXwjgMlF4X6o9W3lKd4uZw

The redirection is then made server side so the code in abc.go.comwebsite might not get proper referrer.

然后重定向在服务器端进行,因此abc.go.com网站中的代码可能无法获得正确的引用。

回答by Konrad Borowski

javascript:alert(document.referrer);

When you will insert it at address bar, the previous location will appear, like the addresses appear on address bar, like http://php.net/manual/en/control-structures.break.php. You can use it to make complex JavaScript operations, like regular expressions. I will give very simple example

当您将其插入地址栏时,会出现之前的位置,就像地址栏上出现的地址一样,例如http://php.net/manual/en/control-structures.break.php。您可以使用它来进行复杂的 JavaScript 操作,例如正则表达式。我将举一个非常简单的例子

<script type="text/javascript">
if (document.referrer.search('google')==-1){
    alert('Not using Google');
} else {
    alert('Yes, from Google');
}
</script>