Javascript 获取url中哈希标记#后的所有内容
我有一个这样的urlJavascript 获取url中哈希标记#后的所有内容,javascript,php,hashtag,Javascript,Php,Hashtag,我有一个这样的urlhttp://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我什么也得不到。 我知道#是用于客户端/浏览器的,但是有没有办
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
我什么也得不到。
我知道#是用于客户端/浏览器的,但是有没有办法在#(散列标记)之后获取所有内容 URL片段根本不会发送到服务器
您可以使用
location.hash
在客户端Javascript中访问它,您可以使用window.location.hash
var hash=location.hash.slice(1)
来解析url,也可以使用Javascript来代替window.location.hashvar hash=location.hash.slice(1)
来获取#之后的所有内容
对于http://example.com/#hello=1234
var hash将是hello=1234@abracadver在downvoting之前,在您的回答中要更有建设性我尝试了类似的方法,但我是空的警报(window.location.hash)代码>