使用ALT + TAB切换程序/窗口或单击任务栏时,不会触发visibilitychange事件 [英] visibilitychange event is not triggered when switching program/window with ALT+TAB or clicking in taskbar

查看:188
本文介绍了使用ALT + TAB切换程序/窗口或单击任务栏时,不会触发visibilitychange事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,问题是事件visibilitychange的行为。

Basically, the problem is with the behaviour of the event "visibilitychange".

触发:
- 当我切换到浏览器窗口中的其他选项卡

It's triggered: - when i switch to a different tab inside the browser window


  • 当我点击浏览器窗口的最小化/还原按钮

(没关系)

没有触发:
- 当我切换到不同的窗口/程序时使用ALT + TAB

It's not triggered: - when i switch to a different window/program using ALT+TAB


  • 窗口/程序单击任务栏

(这应该触发,因为,就像最小化时,窗口的可见性可能会改变)

W3页面可见性API文档 http://www.w3.org/TR/page-visibility/

关于ALT + TAB /程序切换的页面可见性没有定义在规格表中。我猜想它在操作系统和浏览器之间有所作为。


  • 浏览器
    Chrome 40.0.2214.115 m / Firefox 36.0.1 / Internet Explorer 11.0.9600.17107

  • 操作系统:Windows 8.1

  • Browsers: Chrome 40.0.2214.115 m / Firefox 36.0.1 / Internet Explorer 11.0.9600.17107
  • OS: Windows 8.1

有没有解决方法来解决这个问题?该实现相当简单,我使用jQuery收听visibilitychange事件,然后在其回调中,检查document.visibilityState的值,但问题是事件在预期时未触发。 p>

Is there a workaround to fix this behaviour? The implementation is fairly simple, I listen to the "visibilitychange" event using jQuery, and then in its callback, I check for the value of "document.visibilityState", but the problem is that the event is not firing when expected.

$(document).on('visibilitychange', function() {

    if(document.visibilityState == 'hidden') {
        // page is hidden
    } else {
        // page is visible
    }
});

这样做也可以不用jQuery,但ALT + TAB和任务栏切换隐藏/显示预期行为仍然缺少:

This can be done without jQuery too, but the ALT+TAB and taskbar switch hide/show expected behaviour is still missing:

if(document.addEventListener){
    document.addEventListener("visibilitychange", function() {
        // check for page visibility
    });
}

我也尝试过ifvisible.js模块( https://github.com/serkanyersen/ifvisible.js ),但行为是一样的。

I've also tried the ifvisible.js module (https://github.com/serkanyersen/ifvisible.js) but the behaviour is the same.

ifvisible.on('blur', function() {
    // page is hidden
});

ifvisible.on('focus', function() {
    // page is visible
});

我还没有在其他浏览器上测试,因为如果我无法使其在Chrome上的Windows我真的不在乎其他浏览器。

I haven't tested in other browsers because if I can't make it work in Chrome on Windows I really don't care about the other browsers yet.

提前感谢任何帮助或建议。

Any help or suggestion is in advance thanked.

我尝试为事件名称(visibilitychange,webkitvisibilitychange,mozvisibilitychange,msvisibilitychange)使用不同的供应商前缀,但仍然当我切换到任务栏或ALT + TAB中的其他程序时,或者即使我打开窗口中的开始菜单中的Windows键,覆盖了整个屏幕,事件也不会触发。

I tried using different vendor prefixes for the event name (visibilitychange, webkitvisibilitychange, mozvisibilitychange, msvisibilitychange) but but still the event is not triggered when I switch to a different program in the taskbar or ALT+TAB, or even if I open the start menu thing in windows with the windows key, which covers the whole screen.

我可以在Chrome,Firefox和Internet Explorer中重现完全相同的问题。

I can reproduce the exact same issue in Chrome, Firefox and Internet Explorer.

这里是我为这个问题写的一个综合报告a在纯JavaScript中找到解决方法来解决遇到的问题。

Here's a roundup post I wrote for this issue and a workaround in pure javascript to solve the encountered problems.

推荐答案

这是一个我为这个问题写的综合报告,并且是纯JavaScript的解决方法解决遇到的问题。

Here's a roundup post I wrote for this issue and a workaround in pure javascript to solve the encountered problems.

这篇关于使用ALT + TAB切换程序/窗口或单击任务栏时,不会触发visibilitychange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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