且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么 URL 的哈希部分在服务器端不可用?

更新时间:2022-05-19 17:38:27

不,它只对浏览器可用,所以你必须用 Javascript 来处理它.服务器无法读取.

No, it is available to the browser only, so you have to deal it with Javascript. The server can not read it.

解释:
基本上页面 URL 的哈希组件(# 符号后面的部分)仅由浏览器处理 - 浏览器从不将其传递给服务器.遗憾的是,这是 HTML 标准的一部分,无论您使用的是 IE 还是任何其他浏览器(就此而言,PHP 或任何其他服务器端技术)都是一样的.

Explanation:
Basically the hash component of the page URL (the part following the # sign) is processed by the browser only - the browser never passes it to the server. This sadly is part of the HTML standard and is the same whether or not you are using IE or any other browser (and for that matter PHP or any other server side technology).

以下是***对此的评价:

Here's what Wikipedia says about it:

片段标识符的功能与 URI 的其余部分不同:即,它的处理完全在客户端进行,没有服务器的参与.当代理(例如 Web 浏览器)从 Web 服务器请求资源时,代理将 URI 发送到服务器,但不发送片段.而是代理等待服务器发送资源,然后代理根据分片值对资源进行处理.在最常见的情况下,代理将网页向下滚动到具有等于片段值的属性字符串的锚元素.其他客户端行为是可能的

The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the server. When an agent (such as a Web browser) requests a resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the fragment value. In the most common case, the agent scrolls a Web page down to the anchor element which has an attribute string equal to the fragment value. Other client behaviors are possible