获取完整的URL,包括查询字符串和锚点 [英] Get entire URL, including query string and anchor

查看:171
本文介绍了获取完整的URL,包括查询字符串和锚点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法在包含的页面中获取用于请求当前页面的整个URL,包括锚点(#后面的文本-我可能使用了错误的单词)?

Is there a way to get the entire URL used to request the current page, including the anchor (the text after the # - I may be using the wrong word), in included pages?

即foo.php页面包含在bar.php中.如果我在foo.php中使用您的解决方案,则需要说出bar.php?blarg = a#blahblahblah

i.e. page foo.php is included in bar.php. If I use your solution in foo.php, I need it to say bar.php?blarg=a#blahblahblah

推荐答案

不,恐怕不是,因为哈希(字符串包括#)永远不会传递到服务器,因此仅仅是浏览器的行为属性. $_SERVER['REQUEST_URI']变量将包含其余部分.

No, I am afraid not, since the hash (the string including the #) never gets passed to the server, it is solely a behavioural property of the browser. The $_SERVER['REQUEST_URI'] variable will contain the rest however.

如果您真的需要知道哈希是什么,则必须使用document.location.hash JavaScript属性,该属性包含哈希的内容(然后您可以将其插入表单中,或通过以下方式将其发送到服务器:一个ajax请求).

If you really need to know what the hash is, you will have to use the document.location.hash JavaScript property, which contains the contents of the hash (you could then insert it in a form, or send it to the server with an ajax request).

这篇关于获取完整的URL,包括查询字符串和锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆