urlencode javascript
var url = encodeURIComponent('url');
js urlencode
/* There are 11 characters which are not encoded by encodeURI,
but encoded by encodeURIComponent. */
encodeURI("test uri");
// "test%20uri"
encodeURI("test uri");
// "test%20uri"
encodeURI("test uri/with a slash");
// "test%20uri/with%20a%20slash"
encodeURIComponent("test uri/with a slash");
// "test%20uri%2Fwith%20a%20slash"
js parse url encode
var set1 = ";,/?:@&=+$#"; // Caracteres reservados
var set2 = "-_.!~*'()"; // Marcas não reservadas
var set3 = "ABC abc 123"; // Caracteres alfanuméricos + Espaço
console.log(encodeURI(set1)); // ;,/?:@&=+$#
console.log(encodeURI(set2)); // -_.!~*'()
console.log(encodeURI(set3)); // ABC%20abc%20123 (o espaço é codificado como %20)
Encode URL in JavaScript?
Check out the built-in function encodeURIComponent(str) and encodeURI(str).
In your case, this should work:
var myOtherUrl =
"http://example.com/index.html?url=" + encodeURIComponent(myUrl);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us