node-webkit右键单击链接并在默认浏览器中打开

我在我的node-webkit应用程序中有一个iframe。 我希望用户能够右键单击iframe中的链接(标签),并能够select“在浏览器中打开”选项以使用其系统的默认浏览器打开链接。

这可能吗?

是的,这是可能的,下面是每个文件的代码。

你可以在这里下载整个文件

INDEX.HTML

<iframe src="iframe.html" frameborder="2" height="200px" width="100%" ></iframe> 

Iframe.html的

 <body style="background:#cecece;"> <h2>This is an iFrame</h2> <a href="#" id="link">Right click here</a> <script> // Load native UI library var nw = require('nw.gui'); // Create an empty menu var menu = new nw.Menu(); // Add an item with label menu.append(new nw.MenuItem({ label: 'open in browser', click: function(e) { nw.Shell.openExternal('http://google.com'); } })); // Listen for a right click on link document.getElementById('link').addEventListener('contextmenu', function(e) { e.preventDefault(); menu.popup(ex, ey); }); </script> </body> 

的package.json

 { "name": "NW APP", "main": "index.html", "description": "Contextmenu from within an iframe" }