使用返回按钮恢复到页面的previous状态 [英] Using the BACK button to revert to the previous state of the page
问题描述
我想为我的网站的一个新功能。我想通过隐藏/显示做简单的导航< DIV>
元素
I am trying a new functionality for my web site. I want to do simple navigation by hiding/showing <div>
elements.
例如,当用户点击某些商品的详细信息按钮,我想隐藏主&LT; DIV&GT;
键,显示&LT; DIV&GT;
包含细节的产品
For example, when a user clicks a "details" button on some product, I want to hide the main <div>
and show the <div>
containing the details for the product.
问题是,要回去了previous页,我不得不撤消所有显示/可见样式的变化,这是确定的,如果用户点击在新打开的关闭按钮&LT; DIV&GT;
。但是,大多数用户会点击后退按钮。
The problem is that to go back to the previous "page", I have to undo all the display/visibility style changes, which is ok if the user clicks the "close" button in the newly opened <div>
. But most users will hit the BACK button.
有没有一种方法,使BACK按钮返回页面即的previous状态,撤消能见度/显示器的变化?
Is there a way to make the BACK button go back to the previous "state" of the page i.e., undo the visibility/display changes?
感谢。
推荐答案
要回答你的标题的问题(这就是我一直在寻找)
to answer the question of your title (that's what I was looking for)
使用返回按钮恢复到页面的previous状态
Using the BACK button to revert to the previous state of the page
和来自@ reach4thelasers的答案的链接,你必须设置一个计时器,并再次检查,并再次当前锚:
and from the link from @reach4thelasers's answer, you have to set up a timer and check again and again the current anchor:
//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
setInterval("checkAnchor()", 300);
});
因为没有JavaScript回调触发时返回
按钮pssed $ P $,只锚改变...
because there's no Javascript callback triggered when the BACK
button is pressed and only the anchor is changed ...
-
对了,你在谈论现在被称为的 格局单页界面 的!
by the way, the pattern you're talking about is now known as Single Page Interface !
这篇关于使用返回按钮恢复到页面的previous状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!