解析 JavaScript 中的 URL 查询参数
我正在使用 javascript,需要解析出一个 URL 的查询参数:
/folderone/two?link=http%3A%2F%2Fwww.cooldomainname.com
这非常困难,因为我不仅需要解析出查询参数“link”,而且一旦我有了它,“://”似乎变成:“%3A%2F%2F”
我到目前为止做到了这一点:
url.replace(/^.*\=/, '');
这给我留下了:
http%3A%2F%2Fwww.cooldomainname.com
但现在我仍然需要处理这些“%3A%2F%2F”我可以做一个查找并替换,但我觉得必须有某种类型的库我应该用来“de-URLify”查询参数?
I'm using javascript and need to parse out a query argument that is a URL:
/folderone/two?link=http%3A%2F%2Fwww.cooldomainname.com
This is doubly hard because I not only need to parse out the query argument "link", but once I have that, the "://" seems to have been turned into: "%3A%2F%2F"
I got so far as to do this:
url.replace(/^.*\=/, '');
Which left me with:
http%3A%2F%2Fwww.cooldomainname.com
But now I still need to handle these "%3A%2F%2F" I could just do a find and replace, but I feel like there must be some type of library that I should be using to "de-URLify" query arguments?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用:
输出:
另请注意,我认为
split
是比replace
更自然的选择:(假设您的输入字符串只有一个参数。)
Use:
Output:
Note also that I think
split
is a more natural choice thanreplace
:(It's assumed that your input string has just the one parameter.)