I apologize for vague title so let me explain.
Suppose you have a page with search results: http://example.com/search?q=foo. The results are:
- Foo – http://example.com/foo
- Bar – http://example.com/bar
- Baz – http://example.com/baz
The links above point to the item details page. On these pages I want to display links which allow to navigate through search results: Next Item, Previous Items, Back to Search Results.
So when generating a details page I need to know where the user came from, for instance I need to know which search term he used.
I could add additional query params in URLs, like http://example.com/foo?from=search&q=foo but I can’t do that. The requirement is not to add any additional params to items’ URLs.
Another option is to save search query in session. But it does not work if user opens several search result pages in different tabs.
How would you do that?
PS. I know there is a number of similar questions here but didn’t find the one that can help in my case.
So I came up with the following solution.
I add
onclickhandler to all item links on search results page. This handler sets a session cookie with Javascript. This cookie contains the information about current search query.On item details page I parse this cookie to retreive the information about the search query. It allows me to find next/previous items in search results and add the “Back to search results” link.
This approach works even if user has several search results pages opened in different tabs.