[英]parse hash of URL from ajax call jquery
let say i have this script. 假设我有这个脚本。
$('body').load('someurl.html#12', function(data){
// my code to proccess data
});
in someurl.html
how do i get the hash of this URL? 在
someurl.html
如何获取该URL的哈希? in this case should be #12
. 在这种情况下应该是
#12
。 when i try to parse it using window.location.hash
what i get is the parent URL without hash of course. 当我尝试使用
window.location.hash
解析它时,我得到的是父URL,当然没有哈希。
That can be done using jQuery BBQ Full reference from here 可以使用jQuery BBQ 从这里获取完整参考
Parsing the query string or fragment from a URL
从URL解析查询字符串或片段
The jQuery.param.querystring and jQuery.param.fragment methods can be used to return a normalized query string or fragment from the current document or a specified URL. Complete usage information is available in the documentation.
// Return the document query string (similar to location.search, but with
// any leading ? stripped out).
var qs = $.param.querystring();
// Return the document fragment (similar to location.hash, but with any
// leading # stripped out. The result is *not* urldecoded).
var hash = $.param.fragment();
// Parse URL, returning the query string, stripping out the leading ?.
// qs is set to "a=1&b=2&c=3"
var qs = $.param.querystring( "/index.php?a=1&b=2&c=3#hello-world" );
// Parse URL, returning the fragment, stripping out the leading #.
// hash is set to "hello-world"
var hash = $.param.fragment( "/index.php?a=1&b=2&c=3#hello-world" );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.