Check out the built-in function encodeURIComponent(str)
and encodeURI(str)
.
In your case, this should work:
var myOtherUrl = "http://example.com/index.html?url=" + encodeURIComponent(myUrl);
You have three options:
escape()
will not encode:@*/+ will encode http:// to http%3A//
encodeURI()
will not encode:~!@#$&*()=:/,;?+'
encodeURIComponent()
will not encode:~!*()'
sources: http://stackoverflow.com/questions/332872/how-to-encode-a-url-in-javascript
liked this article?
- only together we can create a truly free world
- plz support dwaves to keep it up & running!
- (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
- really really hate advertisement
- contribute: whenever a solution was found, blog about it for others to find!
- talk about, recommend & link to this blog and articles
- thanks to all who contribute!