Using node webkit, I'm trying to open a new window from the click of a button in the initial window, and at various points write to a textarea in the new window when running node.js code in the initial window context.
The initial window (index.html) contains the following js:
window.gui = require('nw.gui');
var win = gui.Window.open('console.html', {
position: 'center',
width: 1000,
height: 280
});
win.on ('loaded', function(){
var parameters = {greeting: "Hello World"}
win.emit("data", parameters);
});
This is part of a function which is called by the button click, which should create a new window, and then emit variables which can be listened for in the new window.
console.html is setup with the following:
<section>
<div class="log_window">
<textarea id="log_output" cols="80" rows="10"></textarea>
</div>
</section>
<script type="text/javascript">
var gui = require('nw.gui');
var win = gui.Window.get();
win.on("data", function(data) {
document.getElementById('log_output').value = data.greeting;
});
</script>
When the button is pressed, I get the following error:
win.on ('loaded', function(){
^
TypeError: Cannot read property 'on' of undefined
I really don't know what's going on here - is there an issue with the event contexts?