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);