简体   繁体   English

在javascript中处理浏览器后退按钮

[英]Handling browser back button in javascript

I need to handle the browser back button in javascript. 我需要在javascript中处理浏览器后退按钮。 I have implemented the tabs functionality in JS. 我在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. 并在javascript中检查相同。

But how do I make sure that a function gets called in javascript when the user hits the back button. 但是,当用户点击后退按钮时,如何确保在javascript中调用函数。 some help would be appreciated. 一些帮助将不胜感激。

This plugin (from jQuery tools) does exactly what you want. 这个插件 (来自jQuery工具)正是你想要的。

HTML: 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: 使用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) ? 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. 基本上,它基于dhtmlhistory对象,它改变了浏览器中的url。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM