Languages
[Edit]
EN

JavaScript - encode / escape URL characters

25 points
Created by:
Root-ssh
178170

In this short article, we would like to show how in JavaScript, use encodeURIComponent() function to escape all unsafe characters in some URL.

Quick solution:

or:

 

Explaination

Edit

encodeURIComponent() function converts/escapes characters in the following way:

Not escaped characters

Digits, small and big English letters:
0-9 a-z A-Z

Some special characters:
~ ! * - _ . ' ( )
Escaped characters

Non-English alphabets.
e.g. 日本 Россия ąćęłńóśźż etc.

Reserved symbols in URL / URI:
@ : / ? # & =

Unicode characters like emoji, icons, symbols, etc.
e.g. 🚀 🍏 🍌 ❤️ 💻 🙂

  \t \n - spaces, tabulators, newlines, etc.
Characters that are not counted in the Not escaped characters column.

Runnable examples:

 

See also

Edit
  1. JavaScript - decode url characters

  2. JavaScript - base64 with Unicode support

  3. TypeScript - encode / escape URL characters

Alternative titles

  1. JavaScript - encodeURIComponent() function example
  2. JavaScript - encode / escape URL request parameter values
  3. JavaScript - encode URI component function example
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join