从其他页面加载后退按钮后的 History.js 状态
我正在尝试使用 History.js 来跟踪已操纵的 ui 状态JavaScript。目的是用户希望以他们离开的状态返回页面(通过链接访问系统中的其他页面后)。
为此,我为 popstate
绑定了事件,如下所示
History.Adapter.bind(window, 'popstate', function () {
var History = window.History;
var State = History.getState();
LoadState(State, true);
});
:在大多数浏览器中工作正常,同时仍在页面中导航,但只有 Chrome 似乎在从另一个页面返回该页面时触发该事件。我也尝试过绑定 statechange
,但它似乎仅在页面内导航时触发,而不是在“反向加载”页面时触发。
我是否正确假设有一种方法可以在返回页面时触发事件?如果是这样,怎么办?
I'm trying to use History.js to track the state of ui that has been manipulated with Javascript. The purpose is that users want to come back to the page (after visiting other pages in the system via links) in the state they left it in.
For this I bind the event for popstate
like such:
History.Adapter.bind(window, 'popstate', function () {
var History = window.History;
var State = History.getState();
LoadState(State, true);
});
Which works fine in most browsers while still navigating in the page, but only Chrome seems to trigger the event when going back to the page from another page. I've tried binding statechange
as well, but it seems to trigger only on in-page navigation and not on "back-loading" a page.
Am I even correct in assuming there is a way to trigger an event when going back to a page? If so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了解决此问题的一个解决方案,即通过声明
history.navigationMode = '兼容'
这使得在从另一个页面返回到该页面后加载该页面时也会触发就绪事件。从那里开始,就可以像往常一样检索历史对象并加载它。
Found one solution to this problem, which is by declaring
history.navigationMode = 'compatible'
This makes the ready-event trigger also when loading the page after going back to it from another page. From there on it's then possible to just retrieve the history object and load it as usual.