0

I need to handle the browser back button in javascript. I have implemented the tabs functionality in JS. So I want the user to return to the exact time from where they navigated to another page.

I can keep the tab # in some hidden input field. and check with the same in javascript.

But how do I make sure that a function gets called in javascript when the user hits the back button. some help would be appreciated.

5
  • it's the other way around. When you load all content through hxr, the back button doesn't behave as the user expects. Commented Aug 30, 2011 at 8:29
  • I think amit means that he has tabs created in JS (not in browser). So navigating away is probably unwanted. But this is just a guess, question is unclear. Commented Aug 30, 2011 at 8:29
  • What he wants is: When user pushes tha browser's navigation buttons the change of tabs should be recognized. Like user goes to Tab 1, 2 and 3, user pushes back button, user lands in tab 2 instead of the previous page. Commented Aug 30, 2011 at 8:33
  • absolutly, my comment was a response to a deleted one (about history.go(-1)) Commented Aug 30, 2011 at 8:46
  • Sebastian Wramba has the clear idea. I want to do exactly that. Commented Aug 30, 2011 at 9:28

3 Answers 3

2

This plugin (from jQuery tools) does exactly what you want.

HTML:

<!-- tabs title --> <ul id="flowtabs"> <li><a id="t1" href="#player_tab">The Player</a></li> <li><a id="t2" href="#plugins_tab">Plugins</a></li> <li><a id="t3" href="#streaming_tab">Streaming</a></li> </ul> <!-- tabs content --> <div id="flowpanes"> <div>tab1 html here</div> <div>tab2 html here</div> <div>tab3 html here</div> </div> 

Javascript:

<script src="http://cdn.jquerytools.org/1.2.5/full/jquery.tools.min.js"></script> <script> $(function() { $("#flowtabs").tabs("#flowpanes > div", { history: true }); }); </script> 
Sign up to request clarification or add additional context in comments.

2 Comments

i like this plugin. but the thing is the whole tab functionality is already put in place and i cannot tinker around with the way things are structured.
You can still study how jQuery tools makes it: github.com/jquerytools/jquerytools/tree/master/src/tabs
0

how about history.go(-1) ?

$(function(){ $("#myLink").click(function(){ history.go(-1); }); }); 

Comments

0

I invite you to read this article.

Basically, it's based on the dhtmlhistory object, and it change the url in the browser.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.