我现在搜索了几个小时,关于如何使用node将一个变量传递给一个新打开的窗口。
任务非常简单(比如HTTP ),但是在nwj (Node)文档中没有关于这一点的任何信息。
用于打开新窗口的代码:
var win = gui.Window.open ('print.html', {
position: 'center',
width: 901,
height: 127
});
win.on ('loaded', function(){
// the native onload event has just occurred
var document = win.window.document;
});
谢谢!
发布于 2015-11-24 06:50:21
您可以使用"emit“函数将数据传递到新窗口。然后,只需拦截此事件,就可以从传入的对象中提取参数。
例如,在您的index.html中:
<html>
<head>
<script type="text/javascript">
window.gui = require('nw.gui');
var win = gui.Window.open ('print.html', {
position: 'center',
width: 901,
height: 127
});
win.on ('loaded', function(){
var parameters = {greeting: "Hello World"}
win.emit("data", parameters);
});
</script>
</head>
<body>
</body>
</html>
然后在你的print.html中:
<html>
<head>
<script type="text/javascript">
var gui = require('nw.gui');
var win = gui.Window.get();
win.on("data", function(data) {
document.write(data.greeting);
});
</script>
</head>
<body>
</body>
</html>
发布于 2020-03-07 11:00:17
根据当前的nwjs文档,更新的代码如下:
index.html
...<script>let RVal
nw.Window.open('print.html', {},win=>win.on('loaded', () =>RVal=win.window.prnFunc(someData)))</script>...
print.html
...<script>function prnFunc(theData){alert(theData); return 4*theData/*or some such*/}</script>...
https://stackoverflow.com/questions/33812559
复制相似问题