How to encode URL in JavaScript

2 Answers

0 votes
URL = "https://www.seek4info.com/search.php?query=web+hosting+";

let encodedURL = encodeURIComponent(URL);

console.log(encodedURL);


  
    
    
/*
run:

"https%3A%2F%2Fwww.seek4info.com%2Fsearch.php%3Fquery%3Dweb%2Bhosting%2B"
    
*/

 



answered Jan 29, 2021 by avibootz
0 votes
URL = "https://www.seek4info.com/search.php?query=web hosting &order=rand";

let encodedURL = encodeURI(URL);

console.log(encodedURL);


  
    
    
/*
run:

"https://www.seek4info.com/search.php?query=web%20hosting%20&order=rand"
    
*/

 



answered Jan 29, 2021 by avibootz

Related questions

3 answers 245 views
2 answers 164 views
2 answers 224 views
2 answers 241 views
241 views asked Jul 22, 2016 by avibootz
2 answers 254 views
1 answer 171 views
1 answer 232 views
...