javascript document.referrer 用法

document对象的referrer属性,返回导航到当前网页的超链接所在网页的URL。

举例:
1. a.html文件内容如下:
<a href="https://www.jb51.net/article/b.html">浏览b.html </a>
2. b.html文件中的内容如下:
<body>
<script type="text/javascript">
document.write(document.referrer);
</script>
</body>

3. 则在通过a.html中的超链接访问b.html的时候,显示的结果是:
:8180/a.html

说明:

经过测试,需要将两个文件放在服务器中才能得到想要的结果,若直接在本地文件夹中则得到空字符串,若直接在浏览器地址栏中输入b.html的URL地址或使用打开菜单访问b.html,则document.referrer的值为空字符串。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjwfsw.html