gpt4 book ai didi

javascript - 在 NW.js 中打开没有菜单栏的新窗口

转载 作者:太空宇宙 更新时间:2023-11-04 16:11:06 24 4
gpt4 key购买 nike

嗨,我有一个使用 NW.JS 和 angularjs 的应用程序。但问题是,我想打开一个新窗口(从应用程序内加载新页面),而不从主窗口的菜单继承菜单栏。这在nwjs中可能吗?此外,每次我单击主窗口菜单栏中触发新窗口打开的菜单项时,它总是打开新窗口。我怎样才能防止这种情况发生?我的意思是,当我已经打开新窗口时,应用程序应该避免再次打开它,除非它已经关闭。

在我的index.html

var menu = new nw.Menu({ type: 'menubar' });

var submenu = new nw.Menu();
submenu.append(new nw.MenuItem({
label: 'Exit',
click: function(){
nw.App.quit();
}
}));

menu.append(new nw.MenuItem({
label: 'File',
submenu: submenu
}));
menu.append(new nw.MenuItem({
label: 'New Page',
click: function(){
nw.Window.open('index.html#/new_page')
}
}));

nw.Window.get().menu = menu;

最佳答案

当打开新窗口时,您使用的是相同的 html 文件,其中包含创建菜单栏的代码,因此显然也会为弹出窗口创建菜单栏,您需要为弹出窗口使用不同的 html 文件。

下面是完整版本的代码,如果它不适合您,请告诉我

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Demo</title>

<script type="text/javascript">
//var win = nw.Window.get();
//win.showDevTools();

var menu = new nw.Menu({ type: 'menubar' });

var submenu = new nw.Menu();
submenu.append(new nw.MenuItem({
label: 'Exit',
click: function(){
nw.App.quit();
}
}));

menu.append(new nw.MenuItem({
label: 'File',
submenu: submenu
}));
menu.append(new nw.MenuItem({
label: 'New Page',
click: function(){
console.log('open new page');
var parentWin = window;

if(parentWin.localStorage.getItem('child_open')) {
console.log('child window is already open');
return;
}

nw.Window.open('home.html#new_page', {}, function(win) {
parentWin.localStorage.setItem('child_open', true);

win.on('closed', function() {
parentWin.localStorage.removeItem('child_open');
});
});
}
}));

nw.Window.get().menu = menu;
</script>
</head>
<body>
</body>
</html>

home.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Inner Window</title>
</head>
<body>
<br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br />
<p id="new_page"> New page section </p>
</body>
</html>

关于javascript - 在 NW.js 中打开没有菜单栏的新窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41488348/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com