【问题标题】:NW.js How to make F11 hot key to switch between full screen window and standard window?NW.js如何让F11热键在全屏窗口和标准窗口之间切换?
【发布时间】:2017-12-10 23:30:59
【问题描述】:

以下代码可以使用F11热键,让浏览器窗口全屏,如何实现第二次按下F11热键,恢复原来的窗口大小?

<!DOCTYPE html>
<html>
<head>
  <script>
nw.App.registerGlobalHotKey(new nw.Shortcut({
  key: "F11",
  active: function () {
    // decide whether to leave fullscreen mode
    // then ...
    nw.Window.get().enterFullscreen();
  }
}));
  </script>
</head>
<body>
</body>
</html>

【问题讨论】:

  • 进入全屏前记住窗口的大小和位置,退出后恢复。

标签: javascript nw.js


【解决方案1】:

我遇到了同样的问题,在做一些研究时发现了这个问题。

你有两个选择:

使用 toggleFullScreen 方法:

nw.App.registerGlobalHotKey(new nw.Shortcut({
  key: "F11",
  active: function () {
    nw.Window.get().toggleFullscreen();
  }
}));

或者使用 if/else 语句:

window.isFullScreen = false;
nw.App.registerGlobalHotKey(new nw.Shortcut({
  key: "F11",
  active: function () {
    if (window.isFullScreen) {
      nw.Window.get().leaveFullscreen();
      window.isFullScreen = false;
    } else {
      nw.Window.get().enterFullscreen();
      window.isFullScreen = true;
    }
  }
}));

两者产生相同的结果,我个人更喜欢 toggleFullScreen 方法,因为代码看起来更干净。

希望这会有所帮助。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-19
  • 1970-01-01
  • 2017-11-27
  • 2018-05-04
相关资源
最近更新 更多