问题
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