Chrome打包应用onblur听众? [英] Chrome packaged app onblur listener?

查看:85
本文介绍了Chrome打包应用onblur听众?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chrome打包应用是否有任何事件监听器来判断应用是否已失去焦点?我正在尝试制作游戏,但是当我改变焦点时,我似乎无法暂停。

Is there any event listeners for a chrome packaged app to tell if the app has lost focus? I'm trying to make a game, but I can't seem to make it pause when I change the focus.

我尝试了一些不同的东西,比如以下,但似乎都没有。

I've tried a few different things such as the following, but none seem to work.

document.onblur = pause;
document.addEventListener('blur', pause, false);

canvas.onblur = pause;
canvas.addEventListener('blur', pause, false);

window.onblur = pause;
window.addEventListener('blur', pause, false);

chrome.app.window.onblur = pause;
chrome.app.window.onBlur = pause;
chrome.app.window.onblurred = pause;
chrome.app.window.onBlurred = pause;
chrome.app.window.addEventListener('blur', pause, false);

chrome.app.window.current().onblur = pause;
chrome.app.window.current().onBlur = pause;
chrome.app.window.current().onblurred = pause;
chrome.app.window.current().onBlurred = pause;
chrome.app.window.current().addEventListener('blur', pause, false);

任何想法?我可以直接将整个列表复制到我的代码中,而不是一个就会暂停。

Any ideas? I can literally copy this entire list into my code and not a single one fires a pause.

我迷失了,谷歌有3个结果与一些不相关的东西,然后更多我省略的重要作品。

I'm lost and Google has 3 results with some non-related things, then more with omitted works that I find important.

推荐答案

AppWindow 只是chrome特定的api,它只提供文档中定义的方法。如果你想使用普通html窗口对象的标准事件,你必须先使用 contentWindow 属性 AppWindow 。示例:

AppWindow is just chrome specific api, which provides only methods defined in documentation. If you want to use standard events from normal html window object, you have to obtain it first, using contentWindow property of AppWindow. Example:

chrome.app.window.current().contentWindow.onblur = function(){console.log("blur")};

这篇关于Chrome打包应用onblur听众?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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