Skip to content

URL escape characters in JavaScript | Example code

  • by

URL escape characters converts characters into a format that can be transmitted over the Internet. URLs can only be sent over the Internet using the ASCII character-set.

Use the JavaScript encodeURIComponent() function to escape characters in URL.

URL escape codes for characters that must be escaped

CharacterURL Escape Codes

HTML Example code URL escape characters

See how the JavaScript function encodes the text.

<!DOCTYPE html>

    var str = "";




URL escape characters in JavaScript

White spaces in URLs

You can use the following characters or strings to represent white space in the query portion of a URL:

  • White space ( )
  • Plus sign (+)
  • URL escape code (%20)
  • String literal escape code ($20)

Do comment if you have any doubts and suggestions on this JS URL topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

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