Javascript 关闭选项卡时忽略visibilitychange

Javascript 关闭选项卡时忽略visibilitychange,javascript,html,Javascript,Html,什么样的条件才能使d.fx.pause(),但关闭选项卡时不会调用code>(因为在我的情况下它是无用的) 您可以在卸载之前在事件中添加一个标志,并在visibilitychange中检查该标志 e、 g var卸载=false; addEventListener(“beforeunload”,function()){ 卸载=真; /*不用*/ console.log(“1:卸载前,可以请求确认”,document.hidden); }); document.addEventListener(

什么样的条件才能使
d.fx.pause(),但关闭选项卡时不会调用code>(因为在我的情况下它是无用的)


您可以在卸载之前在
事件中添加一个标志,并在
visibilitychange
中检查该标志

e、 g

var卸载=false;
addEventListener(“beforeunload”,function()){
卸载=真;
/*不用*/
console.log(“1:卸载前,可以请求确认”,document.hidden);
});
document.addEventListener(“visibilitychange”,函数(){
/*切换时暂停,但卸载时不暂停*/
常数条件=真;/?
log(“2:visibilitychange”,document.hidden);
如果(!卸载和文档隐藏和条件){
//d、 暂停();
console.log(“d.fx.pause()”);
}
});
addEventListener(“unload”,function()){
console.log(“3:卸载”,document.hidden);
});
window.addEventListener("beforeunload", function() {
    /* NOT USED */
    console.log("1: beforeunload, could ask for confirmation", document.hidden);
});

document.addEventListener("visibilitychange", function() {
    /* pause when switching away, but not when unloading */
    const condition = true; // ?
    console.log("2: visibilitychange", document.hidden);
    if (document.hidden && condition) {
      //d.fx.pause();
    }
});

window.addEventListener("unload", function() {
    console.log("3: unload", document.hidden);
});