Home » JavaScript

encodeURI() and decodeURI() functions with example in JavaScript

JavaScript encodeURI() and decodeURI() functions: Here, we are going to learn about the encodeURI() and decodeURI() functions with Example in JavaScript.
Submitted by IncludeHelp, on February 01, 2019

These are the two predefined functions or global functions in JavaScript, which are used to encode and decode a URI. encodeURI() is used to encode the URI and decodeURI() is used to decode the URI.

Example:

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
	<script>
		var uri ="test page.aspx?val=Hello world!!";
		var enc_str = encodeURI(uri);
		var dec_str = decodeURI(uri);
		
		//printing the values
		document.write("Actual URI: " + uri);
		document.write("<br>");
		
		document.write("Encoded URI: " + enc_str);
		document.write("<br>");
		
		document.write("Decoded URI: " + dec_str);
		document.write("<br>");				
	</script>
</body>
</html>

Output

Actual URI: test page.aspx?val=Hello world!!
Encoded URI: test%20page.aspx?val=Hello%20world!!
Decoded URI: test page.aspx?val=Hello world!!





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.