在JavaScript中编码URL

50 阅读1分钟

内容来自 DOC https://q.houxu6.top/?s=在JavaScript中编码URL

如何安全地使用JavaScript对URL进行编码,以便将其放入GET字符串中?

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

我猜您需要在第二行对myUrl变量进行编码?