एन्कोड करने के लिए एक स्ट्रिंग जिसकी हमें आवश्यकता है encodeURIComponent() या encodeURI() और डीकोड . करने के लिए एक स्ट्रिंग जिसकी हमें आवश्यकता है decodeURIComponent() या decodeURI() . प्रारंभ में, हमने एस्केप () . का उपयोग किया है एन्कोड करने के लिए एक स्ट्रिंग लेकिन चूंकि इसे हटा दिया गया है, इसलिए अब हम encodeURI() . का उपयोग कर रहे हैं ।
वाक्यविन्यास-1
encodeURIComponent(string);
वाक्यविन्यास-2
decodeURIComponent(string);
उदाहरण
निम्नलिखित उदाहरण में, प्रारंभ में, एक स्ट्रिंग ली जाती है और एन्कोडेड encodeURI() . का उपयोग करके और बाद में डिकोड decodeURI() . का उपयोग करके . बाद में दोनों एन्कोडेड और डिकोड परिणाम आउटपुट में प्रदर्शित किए गए।
<html>
<body>
<p id = "encoding"></p>
<script>
var str = "Tutorix is the best e-learning platform";
var enc = encodeURI(str);
var dec = decodeURI(enc);
var res = "After encoding: " + enc + "
</br>" + "After Decoding: " + dec;
document.getElementById("encoding").innerHTML = res;
</script>
</body>
</html> आउटपुट
After encoding: Tutorix%20is%20the%20best%20e-learning%20platform After Decoding: Tutorix is the best e-learning platform