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
  • 20,629
  • 3
  • 39
  • 57

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
  • 795,719
  • 175
  • 1,089
  • 1,143
  • 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
  • 137,716
  • 26
  • 137
  • 190