簡體   English   中英

nodewebkit-文檔說該屏幕可以使用,但是使其無法正常工作

[英]nodewebkit - documentation said screen will work, but its getting impossible to make it work

我正在使用最新的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

該腳本將窗口移動到另一個屏幕的中心(如果有)。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM