获取url中哈希标记#后的所有内容

时间:2014-04-28 00:39:35

标签: javascript php hashtag

我有一个这样的网址http://example.com/?hello=1234

使用此

   ob_start();
   var_dump($_GET);
   $result = ob_get_clean();
   print_r($result);

我明白了

 array(1) {
 ["hello"]=>
 string(3) "123"
 }

但是当谈到http://example.com/#hello=1234我什么都没得到。 我知道#是针对客户端/浏览器的,但有没有办法在#(hash标签)之后获取所有内容?

3 个答案:

答案 0 :(得分:3)

根本不会将URL片段发送到服务器。

您可以使用location.hash在客户端Javascript中访问它。

答案 1 :(得分:0)

JavaScript中的

var hash = location.hash.slice(1)会在#之后为您提供所有内容。

对于http://example.com/#hello=1234 var hash将是hello = 1234

答案 2 :(得分:-2)

您必须使用parse_url()解析网址或使用javascript代替window.location.hash