Latest

recent

JavaScript encodeURI() Function

Definition and Usage

The encodeURI() function encodes a string as a URI.

Syntax

encodeURI(URIstring)

Parameter Description
URIstring Required. The URI to be encoded


Tips and Notes

Note: The encodeURI() function encodes special characters, with the exception of:
, / ? : @ & = + $ #. Use the encodeURIComponent() function to encode these characters.
Tip: Use the decodeURI() function to decode URIs encoded with encodeURI().

Example

In this example we use encodeURI() to encode URIs:

<script type="text/javascript">
var test1="£€";
document.write(encodeURI(test1)+ "<br />");
document.write(decodeURI(test1));
</script>

The output of the code above will be:

%C2%A3%E2%82%AC
£€
JavaScript encodeURI() Function Reviewed by 1000sourcecodes on 03:41 Rating: 5
Powered by Blogger.