helavissa
06-16-2009, 10:19 PM
hi!
the title says it:
is it ok to pass strings with spaces trough url?
i tried it and it seems to work, but it also seems to me that more correct way to do it is to use '+' instead of space since that's what php get method does.
i'm using window.location to redirect to another page.
scrappy
06-16-2009, 10:27 PM
As far as I'm aware, the space is not a legal character in URLs. Some browsers may accept it and others not.
itsallkizza
06-16-2009, 10:30 PM
depending on how you generate and load the url, spaces are generally converted into "%20" in the actual url string and then converted back into spaces when read by JS or server-side query string requests.
though i would recommend avoiding spaces, as long as you encode and decode your url querystrings correctly, there's no problem with them.
rnd me
06-16-2009, 10:52 PM
DOM properties like window.location, a.href, script.src, etc, will handle this automatically, just like they fully qualify URLs.
note that "+" is not the same as "%20", so make sure you are using the proper encoding for your context. they are not always interchangeable...
helavissa
06-17-2009, 12:07 AM
thank you for a reply. Could you explain more about:
DOM properties like window.location, a.href, script.src, etc, will handle this automatically, just like they fully qualify URLs.
Does it mean that i can do window.location = string with spaces and it will be ok?
Philip M
06-17-2009, 07:06 AM
var str = "something with spaces";
str = str.replace(/\s+/g,"%20");
window.location = str;
rnd me
06-17-2009, 10:40 AM
thank you for a reply. Could you explain more about:
Does it mean that i can do window.location = string with spaces and it will be ok?
probably