views:

67

answers:

2
+4  Q: 

escape & in url

Hi all

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

+7  A: 

If you need to just escape a URL, I recommend using a JavaScript function such as encodeURIComponent.

Justin Ethier
+2  A: 

Try the URLEncode plugin: http://plugins.jquery.com/project/URLEncode

Chris Schmitz
Really? Someone made a plugin for this? Whats wrong with the standard JS function [`encodeURIComponent()`](https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent)
gnarf
lol I can't even believe this answer got upvoted.
Andy E