views:

23

answers:

2

I need to get the search query from the search query of the address of the page.

What is the safest cross-browser, and most efficient method of getting the string. for example:

q=123&data=true&b=456
//from
http://www.example.com/?q=123&data=true&b=456

And is location.search available on all modern browsers (IE7+, FF, webkit, opera)?

+3  A: 

Yes, location.search is the way to go.

Introduced in JS 1.0, supported by IE 3.0, Netscape 2, Opera 5.12, FF1.0, Konqueror 3.1 and Safari 1.0.

And I guess it is always supported in Chrome considering that the other browsers support it since ages.

Felix Kling
Thank you for the info. Always thought `location.search` was a "new" implementation since ive never seen it used.
digitalFresh
@digitalFresh: I have my information from [ **here** ](http://de.selfhtml.org/javascript/objekte/location.htm#search). It should be reliable. It is in German but I think the icons are self-explanatory ;) The page has been updated last in 2007 so `location.search` is at least there for three years ;)
Felix Kling