The Show
A string to be encoded as a URI. A new string representing the provided string encoded as a URI.
Thrown if
The A–Z a–z 0–9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , #3, left-padded with 0 if necessary. Because lone surrogates in UTF-16 do not encode any valid Unicode character, they cause encodeURI() to throw a URIError .
A–Z a–z 0–9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # The characters on the second line are characters that may be part of the URI syntax, and are only escaped by http://username:[email protected]:80/path/to/file.php?foo=316&bar=this+has+spaces#anchor0, known as "unreserved marks", which do not have a reserved purpose but are allowed in a URI "as is". (See RFC2396) The http://username:[email protected]:80/path/to/file.php?foo=316&bar=this+has+spaces#anchor
Note that http://username:[email protected]:80/path/to/file.php?foo=316&bar=this+has+spaces#anchor5 and http://username:[email protected]:80/path/to/file.php?foo=316&bar=this+has+spaces#anchor6 requests, such as for http://username:[email protected]:80/path/to/file.php?foo=316&bar=this+has+spaces#anchor7, because http://username:[email protected]:80/path/to/file.php?foo=316&bar=this+has+spaces#anchor8, http://username:[email protected]:80/path/to/file.php?foo=316&bar=this+has+spaces#anchor9, and 0 are not encoded, which are treated as special characters in http://username:[email protected]:80/path/to/file.php?foo=316&bar=this+has+spaces#anchor5 and http://username:[email protected]:80/path/to/file.php?foo=316&bar=this+has+spaces#anchor6 requests. encodeURIComponent() , however, does encode these characters.An
The more recent RFC3986 makes square brackets reserved (for IPv6) and thus not encoded when forming something which could be part of a URL (such as a host). It also reserves !, ', (, ), and *, even though these characters have no formalized URI delimiting uses. The following function encodes a string for RFC3986-compliant URL format. How to convert HTML special characters in JavaScript?Convert special characters to HTML in JavaScript. & (ampersand) becomes & .. " (double quote) becomes " when ENT_NOQUOTES is not set.. ' (single quote) becomes ' only when ENT_QUOTES is set.. < (less than) becomes < .. > (greater than) becomes > .. How to encode all special characters in JavaScript?The encodeURI() method encodes a URI.. Note. Use the decodeURI() method to decode a URI.. Special Characters. The encodeURI() method does not encode characters like: , / ? : @ & = + $ * # ... . See Also: The encodeURIComponent() method to encode a URI. The decodeURIComponent() method to decode a URI.. How to encode HTML value in JavaScript?just Call a Function with one argument.... Decode HTML-entities function decodeHTMLEntities(text) { var textArea = document. ... . Decode HTML-entities (JQuery) function decodeHTMLEntities(text) { return $("<textarea/>"). ... . Encode HTML-entities function encodeHTMLEntities(text) { var textArea = document.. How to escape HTML special characters in JavaScript?To use a special character as a regular one, prepend it with a backslash: \. . That's also called “escaping a character”.
|