Handling browser back button in javascript
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.
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>
how about history.go(-1)
?
$(function(){
$("#myLink").click(function(){
history.go(-1);
});
});
I invite you to read this article.
Basically, it's based on the dhtmlhistory object, and it change the url in the browser.
精彩评论