绑定popstate事件不起作用 [英] binding popstate event not working
本文介绍了绑定popstate事件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在浏览器的控制台中键入以下代码:
I have tried to type this code into the browser's console:
window.onpopstate = function() {alert(1);}
,然后单击后退按钮。没有警报显示。
我做错什么了吗?还是不允许将popstate事件从控制台绑定到页面?
and then click the back button. No alert has shown. Am I doing something wrong? Or is it not allowed to bind popstate event to a page from console?
使用Chrome 24和Firefox 18
Using Chrome 24 and Firefox 18
推荐答案
在控制台中将其键入
window.onpopstate = function() {alert(1);}; history.pushState({}, '');
然后单击后退按钮。
这篇关于绑定popstate事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文