如何在Javascript中获取URL的主题标签值和&值? [英] How to get the hashtag value and ampersand value of a url in Javascript?
问题描述
我有一个http://www.example.com/folder/file.html#val=90&type="test"&set="none"&value="reset?setvalue=1&setvalue=45"
现在我需要从#开始获取url的那一部分,如何获取,我尝试使用window.location.search.substr();
,但看起来像在搜索吗?在网址中.有没有一种方法可以在#
Now I need to get the portion of url from starting from #, How do I get that, I tried using window.location.search.substr();
but looks like that searches for ? in a url. is there a method to get the value of url after #
我还如何从&符&中获取部分网址
How do I also get a portion of url from ampersand &
谢谢, 迈克尔
推荐答案
var hash = window.location.hash;
此处的更多信息: https://developer.mozilla.org/en/DOM /window.location
更新:它将抓取井号之后的所有字符,包括所有查询字符串.从MOZ手册中:
Update: This will grab all characters after the hashtag, including any query strings. From the MOZ manual:
window.location.hash === the part of the URL that follows the # symbol, including the # symbol.
You can listen for the hashchange event to get notified of changes to the hash in
supporting browsers.
现在,如果您需要解析查询字符串(我相信您需要这样做),请在此处进行检查:
Now, if you need to PARSE the query string, which I believe you do, check this out here: How can I get query string values in JavaScript?
这篇关于如何在Javascript中获取URL的主题标签值和&值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!