Encode URL in JavaScript

Mots clés : javascripturlencodeurlencodejavascript

meilleur 3 Réponses Encode URL in JavaScript

vote vote

90

var myOtherUrl =         "http://example.com/index.html?url=" + encodeURIComponent(myUrl); 
vote vote

81

const value = encodeURIComponent(value).replace('%20','+'); const url = 'http://example.com?lang=en&key=' + value 
const escapedValue = encodeURIComponent(value).replace('%20','+'); const escapedFolder = encodeURIComponent('My Folder'); // no replace const url = `http://example.com/${escapedFolder}/?myKey=${escapedValue}`; 
vote vote

76

qs.stringify({a:"1=2", b:"Test 1"}); // gets a=1%3D2&b=Test+1 
$.param({a:"1=2", b:"Test 1"}) // gets a=1%3D2&b=Test+1 

Questions similaires