2015-11-19 26 views
4

我正在搜索幾個小時,瞭解如何使用node-webkit將變量傳遞到新打開的窗口。將變量傳遞到一個新打開的窗口 - nwj(node-webkit)

該任務非常簡單(如HTTP POST),但在nwj(node-webkit)文檔中沒有關於此的任何說明。

代碼,我用它來打開新窗口:

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

謝謝!

回答

2

您可以使用「發射」功能將數據傳遞到新窗口。然後,所有你需要做的是攔截此事件,你可以從你所傳遞的對象中提取的參數

例如,在您的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> 
+0

感謝您的幫助和詳細的示例! –

+0

當然 - 我也遇到過困難,偶然發現瞭解決方案。 – Ewald

相關問題