EncodeURI
From PlainOldWebserver
encodeURI()
The encoding scheme preserves the characters "&+=", which you may not want to do. Since these characters are used in query strings, encodeURI() may produce strange results.
var enc_uri = encodeURI(";,/?:@&=+$ ABC &+=");
document.writeln(" Encoded is "+enc_uri);
var dec_uri = decodeURI(enc_uri);
document.writeln(" Decoded is "+dec_uri);
var enc_uri = encodeURIComponent(";,/?:@&=+$ ABC &+=");
document.writeln(" Component encoded is "+enc_uri);
var dec_uri = decodeURIComponent(enc_uri);
document.writeln(" Component decoded is "+dec_uri);
Result:
Encoded is ;,/?:@&=+$%20%20ABC%20&+= Decoded is ;,/?:@&=+$ ABC &+= Component encoded is %3B%2C%2F%3F%3A%40%26%3D%2B%24%20%20ABC%20%26%2B%3D Component decoded is ;,/?:@&=+$ ABC &+=