ajax 支持页面中的后退按钮
我有一个 php 主页面,现在我使用 ajax 在该主页面的 div 中加载不同的页面。现在我想在从属页面上添加一个后退按钮,以便 div 可以加载其前一个从属页面,但后退按钮,我正在使用使用 History.go(-1) ,它使我远离母版页。有没有人有任何解决方案。提前致谢。
我正在使用的代码写在下面。但它在 ajax 页面中不起作用
<a href="javascript:history.go(-1)">Go back</a>
i have a master php page and now i am loading different pages in a div of this master page using ajax. now i want to add a back button on the slave pages so that the div can loaded with its just previous slave page but the back button, i am using uses history.go(-1) that take me away from master page. has anybody any solution. Thanks in advance.
the code i am using is written below. but it is not working in ajax pages
<a href="javascript:history.go(-1)">Go back</a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的建议是使用一个框架来实现此目的,例如 backbone.js
,您可以在其中设置路由就像在服务器端一样。
我认为这是在 ajax 网站上执行此操作的最佳方法。
My suggestions would be to use a framework for this purpose like backbone.js
Where you can setup routes just like on server side.
I feel this is the best way to do this on ajax sites.
阅读有关操作浏览器历史记录的教程。
它提到:
pushState
,它用于在浏览器历史记录中创建“条目”(带有有关状态的附加数据),允许返回到您之前保存的某个特定状态,onpopstate
事件,当您来回浏览浏览器历史记录时触发,并传递先前为历史记录中的特定条目保存的信息(以便您实际上可以读取数据之前保存的pushState
对于这个特定的条目),如果
pushState
和onpopstate
不适合您,仍然有一些能力可以在以下基础上工作onhashchange
事件(但有限)。好消息是,您想要实现的目标绝对是可能的。它甚至在 Twitter、GitHub、Facebook 等许多著名网站中得到实现。
Read tutorial on Manipulating browser history.
It mentions:
pushState
, which is used for creating "entries" in the browser's history (with attached data about state), allowing to get back to some specific state you previously saved,onpopstate
event, that is fired when you go back or forth through the browser's history, and passes information previously saved for specific entry in the history (so you actually can read data previously saved bypushState
for this specific entry),In case
pushState
andonpopstate
do not work for you, there is still some ability to work on the basis ofonhashchange
event (however limited).The good news is that what you want to achieve is definitely possible. It is even implemented in many famous sites such as Twitter, GitHub, Facebook etc.
您可以使用较新浏览器中提供的历史记录功能。有几个库已经为您提供了功能:
对于 JavaScript MVC 应用程序:
http://documentcloud.github。 com/backbone/#History
对于移动网页:
http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/pages/docs-navmodel.html
自行实施解决方案:
http://benalman.com/projects/jquery-hashchange-plugin/
You can use the history functionality provided in newer browser. There is several libs that already provide functionality for you:
For JavaScript MVC applications:
http://documentcloud.github.com/backbone/#History
For mobile web pages:
http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/pages/docs-navmodel.html
For implementing a solution your self:
http://benalman.com/projects/jquery-hashchange-plugin/