admin管理员组文章数量:1323200
How can I escape &
(ampersand) in url with the correct replacement in the jQuery function.
I have tried
.replace("/&/g", "&")
.replace("/&/g", "%26")
.replace("/&/g", "\&")
But nothing is working.
If anyone has idea please share with me.
Thanks
How can I escape &
(ampersand) in url with the correct replacement in the jQuery function.
I have tried
.replace("/&/g", "&")
.replace("/&/g", "%26")
.replace("/&/g", "\&")
But nothing is working.
If anyone has idea please share with me.
Thanks
Share Improve this question edited Sep 3, 2011 at 22:12 Justin Ethier 134k52 gold badges232 silver badges287 bronze badges asked Jun 21, 2010 at 18:02 alienavataralienavatar 2991 gold badge7 silver badges19 bronze badges 2-
.replace(/&/g, "%26")
should work if your JS is external. If it's embedded in your HTML, then you probably need to escape the&
as&
. But, useencodeURIComponent
instead of reinventing the wheel. – Ateş Göral Commented Jun 21, 2010 at 18:07 - 1 This really has nothing to do with jQuery - string replacement operations are plain old JavaScript – gnarf Commented Jun 21, 2010 at 18:21
3 Answers
Reset to default 9If you need to just escape a URL, I remend using a JavaScript function such as encodeURIComponent.
Try the URLEncode plugin: http://plugins.jquery./project/URLEncode
Stumbled on this old posting looking for something else. Just wanted to add that the original poster's question had to do with asking why
string.replace("/&/g", "&")
wasn't working. The appropriate syntax for this should have been:
string.replace(/&/g, "&")
The search token, as it was intended to be a regex, needs to be a regex and not a string.
本文标签: javascriptescape amp in urlStack Overflow
版权声明:本文标题:javascript - escape & in url - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742088865a2420145.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论