Reputation: 1276
I'm trying to use this script that will redirect any webpage to another webpage with a query including the previous webpage's URL.
The code I'm attempting to use looks as such:
window.location = "http://www.readability.com/m?url=" + document.URL;
It's not working though, for what reason I can't figure out. I'm not to familiar with encoding, so this may be the problem. As this works...
window.location = "http://www.readability.com"
But this does not work
window.location = "http://www.readability.com/"
Furthmore I'm working with a mobile browser, not anything like chrome. So it may just be an issue with that, but it may not be. Thanks for reading, and thanks in advance for any help.
Upvotes: 0
Views: 129
Reputation: 100090
You need to escape the URL, otherwise it will be cut on the first &
it contains.
window.location = "http://www.readability.com/m?url=" + encodeURIComponent(window.location);
also ignore document.URL
and use a more common and interoperable window.location
instead.
Upvotes: 2
Reputation: 35829
Don't use escape, since it will not escape all characters you need.You need to escape it with encodeURIComponent:
window.location = "http://www.readability.com/m?url=" + encodeURIComponent(window.location);
Upvotes: 2