安裝
package.json
{
"name": "helloworld",
"main": "index.html"
}
index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
shell> nw.exe
<!DOCTYPE html>
<html>
<head>
<title>Context Menu</title>
</head>
<body style="width: 100%; height: 100%;">
<p>'Right click' to show context menu.</p>
<script>
// Create an empty context menu
var menu = new nw.Menu();
// Add some items with label
menu.append(new nw.MenuItem({
label: 'Item A',
click: function(){
alert('You have clicked at "Item A"');
}
}));
menu.append(new nw.MenuItem({ label: 'Item B' }));
menu.append(new nw.MenuItem({ type: 'separator' }));
menu.append(new nw.MenuItem({ label: 'Item C' }));
// Hooks the "contextmenu" event
document.body.addEventListener('contextmenu', function(ev) {
// Prevent showing default context menu
ev.preventDefault();
// Popup the native context menu at place you click
menu.popup(ev.x, ev.y);
return false;
}, false);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>My OS Platform</title>
</head>
<body>
<script>
// get the system platform using node.js
var os = require('os');
document.write('You are running on ', os.platform());
</script>
</body>
</html>