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

孤人 提交于 2019-12-11 14:37:53

问题


I am using latest nodewebkit and running the following code as per documentation ( https://github.com/rogerwang/node-webkit/wiki/Screen ) but its always failing. Can anyone please tell me why i have this error please and how do you fix it?

<!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>

ERROR:

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

回答1:


This script moves the window to the center of the other screen (if there is one).

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


来源:https://stackoverflow.com/questions/26396168/nodewebkit-documentation-said-screen-will-work-but-its-getting-impossible-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!