|
||||||||||||||||||||||||||
JS Tutorial
part i - JS language
Part ii - JS objects
Part ii - Client-Side JS
JS Articles |
JavaScript Frequently Ask Question How to encode and decode a URL string in JavaScript? by Puthyrak Kang June 28, 2008In some cases, you want to pass a query string as a part of URL. You have to ensure the query string does not contain any character that is reserved by the URL syntax. This can be done by using a JavaScript's built-in function escape to encode the query string.
Example:
function urlEncode(msg){
return escape(msg);
}
DisplayIncompatible string: "$5 + $5 = $10;"To decode the encoded URL string back to regular string, you can use unescape function.
Example:
function urlDecode(msg){
return unescape(msg);
}
DisplayEncode URL string: "%245%20+%20%245%20%3D%20%2410%3B" |
References(1) Aland Shalloway & James R. Trott, Design Patterns Explained, Second Edition.(2) Allen Holub, Holub on Patterns, Learning Design Patterns by Looking at Code (3) Eric Evans, Domain-Driven Design, Tackling complexity in the heart of software. Advertisement |
||||||||||||||||||||||||
|
||||||||||||||||||||||||||