admin管理员组文章数量:1332873
As a follow-up question to: Most efficient way to do a horizontal sliding layout, is it possible to make the browser's back and forward button work when using a single page layout like that?
As a follow-up question to: Most efficient way to do a horizontal sliding layout, is it possible to make the browser's back and forward button work when using a single page layout like that?
Share Improve this question edited May 23, 2017 at 11:59 CommunityBot 11 silver badge asked Sep 9, 2012 at 10:28 IMBIMB 15.9k23 gold badges87 silver badges149 bronze badges3 Answers
Reset to default 5You can use the history API in HTML5 to achieve that.
Here are a few resources to get you started:
- http://diveintohtml5.info/history.html
- http://html5demos./history
- https://developer.mozilla/en-US/docs/DOM/Manipulating_the_browser_history
To get support in older browsers as well, there are JavaScript libraries that enable that:
- https://github./browserstate/History.js/
Advanced example by the Chrome team, that uses the history API:
- http://www.20thingsilearned./en-US
Yes, you can use HTML5 history API to implement it.
- Demo: http://html5demos./history
- Docs: http://diveintohtml5.info/history.html
In older way, you can try to use bookmark, e.g.
<html>
<head>
<script type="text/javascript">
function goPage (v) {
var idisplay = v == 'i',
adisplay = v == 'a',
bdisplay = v == 'b';
document.getElementById('anchor_i').style.display = idisplay? 'none' : 'block';
document.getElementById('anchor_a').style.display = adisplay? 'none' : 'block';
document.getElementById('anchor_b').style.display = bdisplay? 'none' : 'block';
document.getElementById('content_i').style.display = idisplay? 'block' : 'none';
document.getElementById('content_a').style.display = adisplay? 'block' : 'none';
document.getElementById('content_b').style.display = bdisplay? 'block' : 'none';
}
</script>
</head>
<body>
<a name="index"></a>
<div id="content_i">
index
</div>
<a id="anchor_i" href="#index" onclick="goPage('i');" style="display: none">to index</a>
<a id="anchor_a" href="#page_a" onclick="goPage('a');">to page_a</a>
<a id="anchor_b" href="#page_b" onclick="goPage('b');">to page_b</a>
<a name="page_a"></a>
<div id="content_a" style="display: none">
page a
</div>
<a name="page_b"></a>
<div id="content_b" style="display: none;">
page b
</div>
</body>
</html>
本文标签: javascriptHow to make browser back and forward work on a single page layoutStack Overflow
版权声明:本文标题:javascript - How to make browser back and forward work on a single page layout? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742306557a2450030.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论