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)?

tcooc
  • 19,794
  • 3
  • 36
  • 55

2 Answers2

3

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
  • 756,363
  • 169
  • 1,062
  • 1,111
  • Thank you for the info. Always thought `location.search` was a "new" implementation since ive never seen it used. – tcooc Aug 04 '10 at 15:19
  • @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 Aug 04 '10 at 15:22
0

Here's a canned answer: how to get GET and POST variables with JQuery?

Community
  • 1
  • 1
Ates Goral
  • 132,912
  • 25
  • 133
  • 189