...

View Full Version : is it ok to pass strings with spaces through url



helavissa
06-16-2009, 11: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, 11: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, 11: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, 11: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, 01: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, 08:06 AM
var str = "something with spaces";
str = str.replace(/\s+/g,"%20");
window.location = str;

rnd me
06-17-2009, 11: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

helavissa
06-17-2009, 05:42 PM
thank you



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum