导航到另一个网址后,菜单停止工作。 现在,我添加了菜单:
var menu = new nw.Menu({
type: 'menubar'
});
var menuItems = new nw.Menu();
menuItems.append(
new nw.MenuItem({
label: 'Surf Google',
click: function() {
window.location.href = 'https://google.com';
}
})
);
menuItems.append(
new nw.MenuItem({
label: 'Surf Github',
click: function() {
window.location.href = 'https://github.com';
}
})
);
menu.append(
new nw.MenuItem({
label: "The Menu",
submenu: menuItems
})
);
var w = nw.Window.get();
w.menu = menu
我创建了一个github分支来显示此问题: 的 https://github.com/wvary/nwjs-firewall-test/tree/tested-menu
以下是如何重现此问题:
git clone https://github.com/wvary/nwjs-firewall-test.git
cd nwjs-firewall-test
git checkout tested-menu
npm run build
./dist/nwjs-firewall-test-1.0.0-mac-x64/nwjs-firewall-test.app/Contents/MacOS/nwjs
应用启动后,点击Google菜单项即可浏览Google网站。 然后单击Github菜单项。它应该冲上Github,但它没有。
答案 0 :(得分:1)
您需要创建一个iframe,它占用整个页面并显示它,并将其src属性设置为您想要访问的网址。
编辑:您需要使用网页视图而不是iframe
HTML:
<webview style="display:none; position:fixed; width: 100%; height:100%; bottom:0; right:0; top:0; left:0;" id="view_iframe"></webview>
JS:
var menu = new nw.Menu({
type: 'menubar'
});
var menuItems = new nw.Menu();
menuItems.append(
new nw.MenuItem({
label: 'Surf Google',
click: function() {
document.getElementById("view_iframe").style.display = "block";
document.getElementById("view_iframe").src = "https://google.com";
}
})
);
menuItems.append(
new nw.MenuItem({
label: 'Surf Github',
click: function() {
document.getElementById("view_iframe").style.display = "block";
document.getElementById("view_iframe").src = "https://github.com";
}
})
);
menu.append(
new nw.MenuItem({
label: "The Menu",
submenu: menuItems
})
);
var w = nw.Window.get();
w.menu = menu