Chrome packaged app onblur listener?

末鹿安然 提交于 2019-12-06 06:59:14

问题


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.

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


回答1:


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")};


来源:https://stackoverflow.com/questions/18264324/chrome-packaged-app-onblur-listener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!