2 Example(s) of Javascript encodeURI functions


Description :

encodeURI is use to encode the URI, In this example, the input is "http://learnkode.com/Examples/Javascript/Javascript encodeURI functions" and this will get converted to "http://learnkode.com/Examples/Javascript/Javascript%20encodeURI%20functions". See the code snippet:


Javascript encodeURI functions Example - 1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="encryptUri()">Encode the uri</button>
<p id="sample"></p>
<script>
function encryptUri() {
    var uri = "my page.asp?name=michael&car=voughan";
    var result = encodeURI(uri);
    document.getElementById("sample").innerHTML = result;
}
</script>

</body>
</html>

Output

Description :

Example 2 of encodeURI: See the code snippet:


Javascript encodeURI functions Example - 2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<p>Encoded URI.</p>
<script>
 document.write(encodeURI('\uD800\uDFFF'));
</script>

</body>
</html>

Output