Search code examples
javascriptcookiesbackbrowser-history

How to go on previous page if i opened a page in another tab?


Is it possible to go in previous page if i opened a page in another tab from search results (only using javascript or cookies)?

I have search page like test.com/search And search result like this:

 1) test.com/search/a
 2) test.com/search/b
 3) test.com/search/c 

Now if i opened any of search result link in new tab test.com/search/b (will be in new tab and i want to go on test.com/search page)


Solution

  • You can store text in cookies. You can redirect to different locations using javascript.

    Write a cookie with the URL you're on, store it, let the user click on another page, hook into the page back event, read the cookie and change the location to the URL you read from the cookie. It is also possible to manipulate the hash part of the URL using JavaScript and to store, for example, JSON encoded information in it. With that it is possible to have bookmarkable URLs which refer to a specific state. This is also used in some [jQuery](http://tkyk.github.com/jquery-history-plugin/ plugins.

    However, hooking in the back button event is not possible without HTML5.

    If you decide to depend on HTML5, you can manipulate the browser history directly.