0

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.

Ostap Hnatyuk
  • 1,116
  • 2
  • 14
  • 20

2 Answers2

2

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.

Kornel
  • 97,764
  • 37
  • 219
  • 309
2

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);
Community
  • 1
  • 1
asgoth
  • 35,552
  • 12
  • 89
  • 98