How To Encode URL In JavaScript Tutorial with Examples? – POFTUT

How To Encode URL In JavaScript Tutorial with Examples?

JavaScript programming language provides different encoding functions with some little differences. These functions can be used to encode the URL. Encoding URL is useful to prevent errors, especially during transmission. Encoding URL will make the URL consist of only UTF-8 characters. For example space, Tilda, etc can be expressed in a proper way by encoding.

JavaScript Encoding Functions

JavaScript provides 3 encoding functions. These functions can be used according to the situation.

  • escape
  • encodeURI()
  • encodeURIComponent()

Encode with escape() Function

escape() is the simplest function that is deprecated in JavaScript version 1.5. It is mainly used to encode strings. * @ - _ + . / are exception which are not encoded by the escape() function. As escape() function is depracated use encodeURI() and encodeURIComponent() functions instead.

Encode with escape() Function

Encode with escape() Function

Encode with encodeURI() Function

encodeURI() function is used to encode Uniform Resource Identifier or URI which is alternatively used for URL.

LEARN MORE  What Is Webpage?

Encode with encodeURI() Function

Encode with encodeURI() Function

Encode with encodeURIComponent() Function

encodeURIComponent() is another function used to encode given URL. encodeURIComponent() function is more useful in order to encode URLs. encodeURIComponent() will encode & properly which can cause jeopardize the integrity of the data.

Encode with encodeURIComponent() Function

Encode with encodeURIComponent() Function

Leave a Reply

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