0

i have a search box,

when users search i am updating the page with search results using ajax (jquery). i want the ability to be to share search results. so i want to update the url at the same time to include the search query.

how can i then extract this query in the action method if users share the url?

tereško
  • 58,060
  • 25
  • 98
  • 150
raklos
  • 28,027
  • 60
  • 183
  • 301

1 Answers1

1

You could just include a 'Share' link with your search results that points to http://www.yoursite.com/search?q=[search terms]

If you are trying to dynamically update the URL in the browser's address bar, then that won't work. Changing the browser's address URL will cause a full reload of that page, which ruins your Ajax work. It would also reload the whole page every time a user typed a letter in the search box.

Justin Morgan
  • 2,427
  • 2
  • 16
  • 19
  • how about something like : http://stackoverflow.com/questions/352343/changing-browsers-address-bar-without-refreshing – raklos Feb 08 '11 at 16:52
  • There may be workarounds using anchors and such that might work on some browsers, but I would generally advise against it. It goes against the semantic goal of the address bar and not guaranteed to behave the way you intend across browsers or even versions of browsers--because it is an avenue for abuse, browsers have changed how they handle the address bar across versions to improve security. Simply displaying a prominent SHARE THIS link seems good enough, has a lower risk of breaking in the future, and doesn't violate the intent of the browser bar. – Justin Morgan Feb 08 '11 at 17:20