How do you safely encode a URL using JavaScript such that it can be put into a GET string?

You can use the built-in function encodeURIComponent(str) and encodeURI(str).

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

Published: January 10 2018

blog comments powered by Disqus