是否可以在window.onPopState中进行e.preventDefault? [英] Is it possible to e.preventDefault in window.onPopState?

查看:174
本文介绍了是否可以在window.onPopState中进行e.preventDefault?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图阻止用户返回我的网络应用程序。为此,我尝试捕获window.onpopstate并添加e.preventDefault来取消后退按钮效果。

Im trying to stop the user from going back in my web app. For this I tried catching the window.onpopstate and added e.preventDefault to cancel the back button effect.

但它似乎没有发生。

window.addEventListener('popstate',function(e){ 
console.log(e); e.preventDefault();  
});

是否无法阻止浏览器的popstate事件?或者我做错了什么?

Is it not possible to prevent the popstate event of browser? Or am I doing something wrong?

推荐答案

根据这个文档,popstate事件不可取消:

According to this documentation, the popstate event is not cancellable:


规格: HTML5
接口:PopStateEvent
Bubbles:


可取消:否
目标:defaultView
默认操作:无

Specification: HTML5
Interface: PopStateEvent
Bubbles: Yes
Cancelable: No
Target: defaultView
Default Action: None

这篇关于是否可以在window.onPopState中进行e.preventDefault?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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