encodeURI encodeURIComponent escape
var uri = “http://www.wrox.com/illegal value.htm#start”;
//”http://www.wrox.com/illegal%20value.htm#start”
alert(encodeURI(uri));
//”http%3A%2F%2Fwww.wrox.com%2Fillegal%20value.htm%23start”
alert(encodeURIComponent(uri));
The URI methods encodeURI(), encodeURIComponent(), decodeURI(), and
decodeURIComponent() replace the escape() and unescape() methods, which
are deprecated in the ECMA-262 third edition. The URI methods are always
preferable, because they encode all Unicode characters, whereas the original
methods encode only ASCII characters correctly. Avoid using escape() and
unescape() in production code.