admin管理员组文章数量:1333710
I just wanted to find my first argument from my url.
like
;sourceid=chrome&ie=UTF-8
I just wanted to string "ix=teb".
How to get that string only.
I just wanted to find my first argument from my url.
like
http://www.google.co.in/webhp?ix=teb&sourceid=chrome&ie=UTF-8
I just wanted to string "ix=teb".
How to get that string only.
Share Improve this question asked Mar 17, 2012 at 6:52 NitzNitz 1,72611 gold badges37 silver badges56 bronze badges2 Answers
Reset to default 6window.location.search.replace("?", "").split("&")[0];
update:
in case there's a variable holding url:
url.substring(url.lastIndexOf("?") + 1).split("&")[0];
You can use a regular expression to read out parts of the URL:
window.location.search.match(/\?([^&$]+)/)[1] // == 'ix=teb'
In the event that there isn't anything in the query string of the URL, this would cause an error, so you should include some type checking like:
var queryStringMatch = window.location.search.match(/\?([^&$]+)/);
if(queryStringMatch) {
// do something with queryStringMatch[1]
}
本文标签: how to get first argument from url in javascriptStack Overflow
版权声明:本文标题:how to get first argument from url in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742338985a2456211.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论