0

我正在使用最新的 nodewebkit 并根据文档(https://github.com/rogerwang/node-webkit/wiki/Screen)运行以下代码,但它总是失败。谁能告诉我为什么我有这个错误,你如何解决它?

<!DOCTYPE html>
<html>
<body>
    <script>
      function ScreenToString(screen) {
        var string = "";
        string += "screen: "+ screen.id;
        return string;
      } 

      var gui = require('nw.gui');
      gui.Screen.Init();
      var string  = "" ; 
      var screens = gui.Screen.screens;

      for(var i=0;i<screens.length; i++) {
        string += ScreenToString(screens[i]);
      }
      document.write(string);
    </script>
</body>
</html>

错误:

Uncaught node.js Error 

SyntaxError: Unexpected end of input
    at Object.parse (native)
    at Screen.screens (screen.js:65:15)
    at file:///C:/Users/xxx/Downloads/node-webkit-v0.11.0-pre-win-x64/node-webkit-v0.11.0-pre-win-x64/test.html:14:28
4

1 回答 1

1

此脚本将窗口移动到另一个屏幕的中心(如果有的话)。

var gui = require('nw.gui');

// initialize the Screen singleton
gui.Screen.Init();

// get the current window
var win = gui.Window.get();

function moveToOtherWindow() {
    for(var i = 0; i < gui.Screen.screens.length; i++) {
        var screen = gui.Screen.screens[i];
        // check if the window is horizontally outside the bounds of this screen
        if (win.x < screen.bounds.x || win.x > screen.bounds.x + screen.bounds.width) {
            // move the window to this screen
            win.x = screen.bounds.x + (screen.bounds.width - win.width) / 2;
            win.y = screen.bounds.y + (screen.bounds.height - win.height) / 2;
            break;
        }
    }
}

moveToOtherWindow();
于 2014-10-16T06:20:18.697 回答