在使用 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/