nodewebkit-文档说该屏幕可以使用,但是使其无法正常工作 [英] nodewebkit - documentation said screen will work, but its getting impossible to make it work
本文介绍了nodewebkit-文档说该屏幕可以使用,但是使其无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用最新的nodewebkit并根据文档运行以下代码( https://github.com/rogerwang/node-webkit/wiki/Screen ),但始终失败.谁能告诉我为什么我有这个错误,以及如何解决?
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>
错误:
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
推荐答案
此脚本将窗口移动到另一个屏幕的中心(如果有).
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();
这篇关于nodewebkit-文档说该屏幕可以使用,但是使其无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文