繁体   English   中英

在firefox和chrome中不触发窗口popstate事件

[英]window popstate event is not triggering in firefox and chrome

我想检测backbutton click事件,因此在jquery中使用window popstate事件。 但它根本不会在任何时候触发。

请参考下面的代码

$(document).ready(function(){
            $(window).on("popstate",function(){
                debugger
            });
        });

也尝试过这种方式。

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

是否需要为此添加任何外部脚本? 或其他需要在我的页面中保密的内容。

您可以使用javascript绑定事件监听器,如下所示:

window.addEventListener('popstate', function(event) {
    alert( "triggered" );
});

我相信您需要先添加历史记录然后再检测回来? 例:

var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "?foo=1");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM