How to encode/decode URL parameters in javascript?

ID : 274540

viewed : 20

Tags : javascripturlencryptionjavascript





Top 3 Answer for How to encode/decode URL parameters in javascript?

vote vote

93

You can use base64. Javascript has native functions to do that :

alert(btoa("category=textile&user=user1")); // ==> Y2F0ZWdvcnk9dGV4dGlsZSZ1c2VyPXVzZXIx 

and to reverse it :

alert(atob("Y2F0ZWdvcnk9dGV4dGlsZSZ1c2VyPXVzZXIx")); // ==> category=textile&user=user1 

Be careful to read the doc if you have unicode strings, it's a little different : https://developer.mozilla.org/en-US/docs/Web/API/Window.btoa

vote vote

83

If you don't looking for serious strong crypto, you can use ROT13:

http://en.wikipedia.org/wiki/ROT13

This is enough for slightly obfuscate keys/values in the your URLs.

vote vote

80

Top 3 video Explaining How to encode/decode URL parameters in javascript?







Related QUESTION?