在URL中使用锚#value,我可以在php中调用并使用这个值吗?
可能的重复:
PHP 可以读取 URL 的哈希部分吗?
你好, 我想要转到网页中名为 bla bla bla 的 div 所在的部分。
使用这个: http://www.mysite.com/mypage#28 我到达那里。
但我还需要在 php 中处理该数字。 # 的作用和 a 一样吗? ($_get) 也是如此吗?
否则我该怎么做?
谢谢
Possible Duplicate:
Can PHP read the hash portion of the URL?
Hi,
I want to go to a part of my web page where a div called bla bla bla is located.
Using this: http://www.mysite.com/mypage#28 I get there.
But I also need that number to process in php. Does the # work like a ? ($_get) as well?
How do I do that otherwise?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我同意 middaparka 的观点,哈希值是客户端值,无法从服务器端加载,就像 Facebook 动态 URL 加载技术一样
,您可以从函数中读取它的值,并调用该函数加载页面来执行您需要的操作。
I agree with middaparka, Hash values is a client side values can not be loaded from server side, as Facebook Dynamic Url Loading technique
so you can read it is value from a function, and call that function onload of page to do what you need.
理论上,您可以使用 parse_url 函数通过 <代码>PHP_URL_FRAGMENT 选项。然而,在实践中,我非常确定不能保证浏览器会将这些信息传递给服务器。 :它不会出现在
$_SERVER['REQUEST_URI']
中,因此无法首先将此信息传递到parse_url
中。)(即 ,您需要通过 JavaScript 获取此客户端并将其转发到服务器。为此,您可以使用
window.location.hash
。例如:
In theory you can use the parse_url function to obtain this, via the
PHP_URL_FRAGMENT
option. However, in practice I'm pretty sure that there's no guarantee that the browser will pass this information to the server. (i.e.: It won't show up in$_SERVER['REQUEST_URI']
, so there's no way to pass this information intoparse_url
in the first place.)As such, you'd need to obtain this client-side via JavaScript and forward it to the server. To do this you can use
window.location.hash
.e.g.:
<script>alert('The hash value is: '+window.location.hash);</script>
有一个 JQuery 插件“hashchange”,您可以使用它在每次哈希值更改时发送 Ajax 请求。您甚至可以为它添加书签。
http://benalman.com/projects/jquery-hashchange-plugin/
签出演示位于 http://benalman.com/code/projects/jquery-hashchange /示例/hashchange/
There is JQuery Plugin "hashchange" using that you can send Ajax request when the hash is changed everytime. You can even bookmark it.
http://benalman.com/projects/jquery-hashchange-plugin/
Check out the demo at http://benalman.com/code/projects/jquery-hashchange/examples/hashchange/