无法在Chrome 77中收听"popstate"事件? [英] Can't listen 'popstate' event in Chrome 77?

查看:353
本文介绍了无法在Chrome 77中收听"popstate"事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要在Chrome 77中监听返回按钮".为此,我知道使用"popstate"事件监听器. 我试过了:

Need to listen 'Back button' in Chrome 77. I know that for this using 'popstate' event listenter. I tried:

window.onpopstate = function (event) {
    console.log("location: " + document.location + ", state: " + JSON.stringify(event.state));
};

window.addEventListener('popstate', (event) => {
    console.log("location: " + document.location + ", state: " + JSON.stringify(event.state));
});

什么都没有.也尝试过调试... 如何调查此事件及其发生的原因(以前曾进行过工作)?

Nothing working. Tried also with debugging... How to investigate this event and why it's happened (worked before)?

推荐答案

根据我的上次经验:

popstate事件仅在页面上存在用户交互时有效.

popstate event only works when there is an user interaction on the page.

例如:

单击屏幕上的任意位置,然后单击返回"按钮.您将被popstate解雇.发出警报以轻松感受到它.

click anywhere on the screen then hit back button. You will get popstate fired . Put an alert to feel it easily.

有关更多详细信息,请参阅: https://nakedsecurity.sophos.com/2019/05/09/chrome-plans-to-save-you-from-sites-that-mess-with -您的后退按钮/

For more detail, please refer: https://nakedsecurity.sophos.com/2019/05/09/chrome-plans-to-save-you-from-sites-that-mess-with-your-back-button/

这篇关于无法在Chrome 77中收听"popstate"事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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