📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
- encodeURL() - The encodeURI() function is used to encode a URI.
- encodeURIComponent() - The encodeURIComponent() function encodes a URI component.
- decodeURI()- The decodeURI() function is used to decode a URI.
- decodeURIComponent() - The decodeURIComponent() function decodes a URI component.
1. Encode URL in JavaScript
- encodeURL() - The encodeURI() function is used to encode a full URI.
- encodeURIComponent() - The encodeURIComponent() function encodes a URI component.
- encodeURL() function encodes special characters, except: , / ? : @ & = + $ #
- encodeURIComponent() function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #
- encodeURI() is meant to encode a full URL
- encodeURIComponent() is meant to encode a single URL parameter value
1.1 Encode URL using encodeURI() function example
var uri = 'https://javaguides.net/?x=шеллы';
var encoded = encodeURI(uri);
console.log(encoded);
try {
console.log(decodeURI(encoded));
} catch(e) { // catches a malformed URI
console.error(e);
}
https://javaguides.net/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B
https://javaguides.net/?x=шеллы
1.2 Encode URL Component using encodeURIComponent() function
var uri = "https://javaguides.net/my test.html?name=ram&age29";
console.log("before encode :: " + uri);
var encode = encodeURIComponent(uri);
console.log("after encode :: " + encode);
var decode = decodeURIComponent(encode);
console.log("after decode :: " + decode);
before encode :: https://javaguides.net/my test.html?name=ram&age29
after encode :: https%3A%2F%2Fjavaguides.net%2Fmy%20test.html%3Fname%3Dram%26age29
after decode :: https://javaguides.net/my test.html?name=ram&age29
2. Decode URL in JavaScript
- decodeURI()- The decodeURI() function is used to decode a URI.
- decodeURIComponent() - The decodeURIComponent() function decodes a URI component.
2.1 Decode URL using decodeURI() function example
var uri = 'https://javaguides.net/?x=шеллы';
console.log("before encode :: " + uri);
var encoded = encodeURI(uri);
console.log("after encode :: " + encoded);
try {
var decoded = decodeURI(encoded);
console.log();
console.log("after decode :: " + decoded);
} catch(e) { // catches a malformed URI
console.error(e);
}
before encode :: https://javaguides.net/?x=шеллы
after encode :: https://javaguides.net/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B
after decode :: https://javaguides.net/?x=шеллы
2.2 Decode URL Component using encodeURIComponent() function
var uri = "https://javaguides.net/my test.html?name=ram&age29";
console.log("before encode :: " + uri);
var encode = encodeURIComponent(uri);
console.log("after encode :: " + encode);
var decode = decodeURIComponent(encode);
console.log("after decode :: " + decode);
before encode :: https://javaguides.net/my test.html?name=ram&age29
after encode :: https%3A%2F%2Fjavaguides.net%2Fmy%20test.html%3Fname%3Dram%26age29
after decode :: https://javaguides.net/my test.html?name=ram&age29
Comments
Post a Comment
Leave Comment