Encode URL in JavaScript? -
how safely encode url using javascript such can put string?
var myurl = "http://example.com/index.html?param=1&anotherparam=2"; var myotherurl = "http://example.com/index.html?url=" + myurl; i assume need encode myurl variable on second line?
check out built-in function encodeuricomponent(str) , encodeuri(str).
in case, should work:
var myotherurl = "http://example.com/index.html?url=" + encodeuricomponent(myurl);
Comments
Post a Comment