有没有办法告诉国家与history.js的方向? [英] Is there a way to tell what direction the state is going with history.js?

查看:73
本文介绍了有没有办法告诉国家与history.js的方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像标题所说,如果 pushState ,我希望能够执行不同的 onstatechange 事件调用函数,而不是后退函数。或者,如果 go 函数为负数或正数。

Like the title says, I'd like to be able to perform a different onstatechange event if the pushState function is called, instead of the back function. Or, if the go function is negative or positive.

示例:

if History.pushState() History.go(1)被调用,我想要 statechange 事件的回调为 forwardPushState

if History.pushState() or History.go(1) are called, i want the statechange event's callback to be forwardPushState

如果 History.back() History.go(-1)被调用,我想要 statechange 事件的回调是 backwardsPushState

if History.back() or History.go(-1) are called, i want the statechange event's callback to be backwardsPushState

推荐答案

状态是与页面相关的一些数据(用户在浏览器中看到它)。如果用户想要进入某个页面,则该页面是相同的,如果他来自后退按钮点击或来自前进按钮点击,我认为。

A state is some data related to a page (as the user see it in the browser). If the user wants to be in a certain page, this page is the same, either if he is coming from back button click or from forward button click, as I think.

PushState在堆栈中推送新状态。它与返回 go 无关。 返回 go 是用于在堆栈中的推送状态上导航的函数。我这样说是因为在你的编辑中,看起来你认为pushState和go(1)是等价的。

PushState pushes a new state in the stack. It has no relationship with back and go. Back and go are functions to navigate over pushed states in stack. I say this because in your edit, it looks like you are thinking that pushState and go(1) are equivalent.

也许你想知道用户的方向即将到来,您应该分析 onstatechange 事件,以了解是否需要存储方向的任何参数。我仍然不知道该怎么做。

Maybe if you want to know from which direction the user is coming, you should analyse onstatechange event to know if it takes any parameter that stores direction. I still don't know how to do.

我认为主要的是它与go ( - 1)没有任何关系 go(1)返回

The main thing I think, is that it has no relationship with the go (-1) or go(1) or back.

这篇关于有没有办法告诉国家与history.js的方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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