如果popstate事件来自使用HTML5 pushstate的后退或前进操作,我该如何检索? [英] How do I retrieve if the popstate event comes from back or forward actions with the HTML5 pushstate?

查看:508
本文介绍了如果popstate事件来自使用HTML5 pushstate的后退或前进操作,我该如何检索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个网页,根据下一步或后面的动作进行相应的动画,使用pushstate时会出现问题。当我收到事件时,我如何知道用户是否使用Pushstate API单击了回退或转发历史记录按钮?或者我必须自己实现某些内容?

解决方案

您必须自己实现它,这非常简单。


  • 当调用 pushState 时,为数据对象提供唯一的递增id(uid)。
  • onpopstate 处理程序被调用;检查包含最后一个状态uid的持久变量的状态uid。
  • 使用当前状态uid更新持久变量。

  • 执行不同的操作如果状态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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆