Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between decodeURIComponent and decodeURI?
decodeURIComponent
To decode a URL component in JavaScript, use the decodeURLComponent() method.
Example
You can try to run the following code to decode a URL component −
<!DOCTYPE html>
<html>
<body>
<button onclick="display()">Check</button>
<p id="demo"></p>
<script>
function display() {
var uri = "http://example.com/welcome msg.jsp?name=åmit&sub=programming";
// first encode
var encode = encodeURIComponent(uri);
var decode = decodeURIComponent(encode);
var result = "Encode= " + encode + "<br>" + "Decode= " + decode;
document.getElementById("demo").innerHTML = result;
}
</script>
</body>
</html>
decodeURI
To decode a URL in JavaScript, use the decodeURI() method.
Example
You can try to run the following code to decode a URL −
<!DOCTYPE html>
<html>
<body>
<button onclick="display()">Check</button>
<p id="demo"></p>
<script>
function display() {
var uri = "welcome msg.jsp?name=åmit&sub=programming";
// first encode
var encode = encodeURI(uri);
var decode = decodeURI(encode);
var result = "Encode= " + encode + "<br>" + "Decode= " + decode;
document.getElementById("demo").innerHTML = result;
}
</script>
</body>
</html>Advertisements