1

The following code can use the F11 hot key, so that the browser window full screen, how to achieve the second press the F11 hot key, restore the original window size?

<!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>
tianyi
  • 357
  • 4
  • 15
  • Remember the size and location of the window before entering full screen, then restore it after exiting. – erikvimz Dec 21 '17 at 18:13

1 Answers1

2

I was facing the same problem, found this question while doing some research.

You have two options:

Using the toggleFullScreen method:

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

Or using an if/else statement:

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

Both produce the same result, I personally prefer the toggleFullScreen method because the code looks cleaner.

Hope this helps.

  • Thank you very much for your help. Can you help me to look at this problem? It has been a month for me. Thank you again. https://stackoverflow.com/questions/47743534/how-to-shortcut-keys-in-the-main-window-and-pop-up-window-to-take-effect – tianyi Dec 24 '17 at 05:23