Global encodeURI() Function - Javascript Global

Javascript examples for Global:encodeURI

Description

The encodeURI() function encodes a URI.

This function encodes special characters, except: , / ? : @ & = + $ # which can be encoded by encodeURIComponent().

Parameter Values

Parameter Description
uri Required. The URI to be encoded

Return Value:

A String, representing the encoded URI

The following code shows how to Encode a URI:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*  w  w w  .j a va2  s  .  c o  m*/
    var uri = "https://examlle.com/my test.asp?name=st?le&car=saab";
    var res = encodeURIComponent(uri);
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

Related Tutorials