Global encodeURIComponent() Function - Javascript Global

Javascript examples for Global:encodeURIComponent


The encodeURIComponent() function encodes a URI component.

This function encodes special characters including: , / ? : @ & = + $ #

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>

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

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

function myFunction() {//ww  w.  ja va2  s . co  m
    var uri = " test.asp?name=st?le&car=saab";
    var res = encodeURIComponent(uri);
    document.getElementById("demo").innerHTML = res;


Related Tutorials