Javascript URLEncode

Let us take a look at what would be the best approach for Encoding URL using Javascript. There are basically 3 Javascript URLEncode methods available.

Types of Javascript URLEncode

  • escape() will not encode: @*/+  :- This method is obsolete and deprecated since ECMAScript v3.  Hence do not use this approach to encoding the URL’s.
  • encodeURI() will not encode: [email protected]#$&*()=:/,;?+’  : – If you need to encode the URL completely then you should use encodeURII() method. Below is the example of how to use encodeuri method
  • encodeURIComponent() will not encode: ~!*()’ :- encodeURIComponent method should be used only to encode the URL parameters/ query string values. Do not encode the actual URL using this method doing so will destroy the URL. Let us take an example of how to use an encodeURIComponent method.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.