javascript - 为什么 document.referrer 没有得到 #

标签 javascript referrer document.write

在使用 document.referrer 时不带出 # 之后的参数是标准的吗?我使用下面的代码只是为了检查我正在构建的脚本:

<script type="text/javascript">
document.write (document.referrer);
</script>

这是理想的,因为我不想在 url 之后发送任何详细信息到我链接到的网站

最佳答案

是的,这是正常的,也是意料之中的。 specification document.referrer 说:

Returns the URI [IETF RFC 2396] of the page that linked to this page. The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark).

还有 URI RFC说:

4.1. Fragment Identifier

When a URI reference is used to perform a retrieval action on the identified resource, the optional fragment identifier, separated from the URI by a crosshatch ("#") character, consists of additional reference information to be interpreted by the user agent after the retrieval action has been successfully completed. As such, it is not part of a URI, but is often used in conjunction with a URI.

所以 document.referrer 包含一个 URI,但是 # 之后的部分不是 URI 的一部分,因此不包括在内。

关于javascript - 为什么 document.referrer 没有得到 #,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49438137/

相关文章:

javascript - 无法将复选框更改为只读

javascript - 将引用者传递到新页面(&Referrer)

javascript - 如何在不清除以前的文本的情况下在 setTimeout 中使用 document.write

php - 重定向,但隐藏推荐人

javascript - 如何从 Firefox 扩展覆盖 JavaScript 函数?

javascript - 尝试使用我可以自定义的表单中的信息创建一个新窗口。卡住

javascript - 从 gulp 文件运行命令

javascript - 使用 .sort() 和 .data() 对 IE11 和 Edge 中的 HTML 元素进行排序

javascript - 在 DOM 加载后添加到 DOM 时,HTML Textarea 不允许我输入内容

android - 不要在 Android 3.x 上获取 Android Market INSTALL_REFERRER