在chrome应用程序示例中添加窗口状态(最大值、最小值等)侦听器

Adding a window state (max,min etc.) listener in chrome app example

本文关键字:最大值 最小值 侦听器 状态 窗口 应用程序 chrome 添加      更新时间:2023-09-26

我正在尝试在窗口状态更改时启动一个函数(js已经有了一个onresize函数,firefox有一个状态更改侦听器,但是从最小值到最大值恢复并不是一个调整大小的事件(。

manifest.json调用main.js:

main.js:[启动index.html]

window.chrome.app.runtime.onLaunched.addListener(function() {
window.chrome.app.window.create('index.html',{id: "index"})});

index.html:[包括一个div,该div应在窗口状态更改时更改通过调用htmlBoundScript.js]

<script src=htmlBoundScript.js></script>
<!--below should change when screen is maximized-->
<div id="window_state">state has not yet changed</div>
<!--it does not change-->

htmlBoundScript.js->[在html中监听状态更改和更新div]

chrome.app.window.onFullscreened.addListener(function()
    {
      var isMax = chrome.app.window.get('index').isMaximized();
      document.getElementById('window_state').innerHTML = 
      ("state has ... changed, isMax = " + isMax);
    });
//The above code does not behave as intended, 
//that is it does not change the div in the html

以下内容:https://developer.chrome.com/apps/app_window#event-on最大化,但我相信有一个基本要素需要调整。

来自SE的链接:

chrome.app.window.current().onBoundsChanged.addListener(updateCurrentStateReadout);
function updateCurrentStateReadout() {
 if(chrome.app.window.current().isMaximized())
 {
   //do action ...
 }
}

然而,仍在搜索如何使用onFullscreen方法的示例。