2 Example(s) of Javascript encodeURIComponent functions


Description :

encodeURIComponent will encode all the characters with special meaning. See the code snippet:


Javascript encodeURIComponent functions Example - 1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="encryptUrIComponent()">Encode the uri component</button>
<p id="sample"></p>
<script>
function encryptUrIComponent() {
    var uri = "http://learnkode.com/Examples/Javascript/Javascript encodeURI functions";
    var result = encodeURIComponent(uri);
    document.getElementById("sample").innerHTML = result;
}
</script>

</body>
</html>

Output

Description :

Example 2 of encodeURIComponent:


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

</body>
</html>

Output