如果popstate事件来自使用HTML5 pushstate的后退或前进操作,我该如何检索? [英] How do I retrieve if the popstate event comes from back or forward actions with the HTML5 pushstate?
本文介绍了如果popstate事件来自使用HTML5 pushstate的后退或前进操作,我该如何检索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个网页,根据下一步或后面的动作进行相应的动画,使用pushstate时会出现问题。当我收到事件时,我如何知道用户是否使用Pushstate API单击了回退或转发历史记录按钮?或者我必须自己实现某些内容?
解决方案
您必须自己实现它,这非常简单。
pushState
时,为数据对象提供唯一的递增id(uid)。
onpopstate
处理程序被调用;检查包含最后一个状态uid的持久变量的状态uid。
I'm developing a webpage where depending on the next or back actions I do the correspondent animation, the problem comes when using the pushstate. When I receive the event how do I know if the user clicked back or forward history buttons using the Pushstate API?, or do I have to implement something myself?
解决方案
You must implement it yourself which is quite easy.
- When invoking
pushState
give the data object a unique incrementing id (uid). - When
onpopstate
handler is invoked; check the state uid against a persistent variable containing the last state uid. - Update the persistent variable with the current state uid.
- Do different actions depending on if state uid was greater or less than last state uid.
这篇关于如果popstate事件来自使用HTML5 pushstate的后退或前进操作,我该如何检索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文