我的电子应用程序中有2个 BrowserWindow 实例, mainWindow 和 secondaryWindow 。 mainWindow 中有一个按钮,单击该按钮应打开 secondaryWindow 。
I have 2 BrowserWindow instances in my electron application, mainWindow and secondaryWindow. There is a button in mainWindow which when clicked should open secondaryWindow.
现在我的问题是我不希望在 secondaryWindow $ c中单击 mainWindow 中的任何内容$ c>已关闭。
Now my issue is that I don't want to be able to click on anything in the mainWindow until the secondaryWindow is closed.
我能得到的最接近的方法是使用 mainWindow.hide(),但这仅仅是完全隐藏了窗口,我想在 The closest I could get was to use mainWindow.hide() but this just completely hides the window, I want to still see the mainWindow while the secondaryWindow is active but it should be disabled / inactive. 有什么建议吗? 有2种打开方法子窗口: There are 2 ways to open a child window: 1。在主流程中: 您可以从主流程中打开一个子窗口。例如,这对于菜单中的自定义窗口很有用。 You can open a child window from the main process. This is for example useful for a custom window in the menu. 在这里,您可以使用构造函数使其成为 parent 的子级。 。如果 modal 属性为true,则在关闭子窗口之前将无法访问父窗口。 Here you can use the constructor to make it a child of parent. If the attribute modal is true, the parent window will not be accessible until the child window is closed. 2。从渲染器进程 现在,我们并不总是希望通过IPC向主进程发送事件只是打开一个子窗口,对吧? Now, we don't always want to send an event over the IPC to the main process just to open a child window, right? 我们不需要。为此,我们可以在窗口中使用 open 函数。 We don't need to. We can use the open function on our window for that. 例如: 使此窗口成为您父母的孩子在模式和模式上,您可以在父窗口上注册事件监听器: To make this window a child of your parent and modal, you can register an eventlistener on the parent window: 使用此功能时,调用 window.open()时父窗口,它将打开一个模态子窗口。 With this, when window.open() is called on the parent window, it will open a modal child window. 示例 main.js index.html index.html child.html child.html 更新电子5或更高 使用电子5时,节点集成被禁用出于安全原因,默认情况下渲染器进程。由于此示例在渲染器过程中使用 __ dirname (这是节点API的一部分),因此我们需要重新引入它,因为它不再可用。在此示例中,我为此目的使用了预加载脚本:
Update Electron 5 or higher
With electron 5 node integration was disabled in the renderer process by default for security reasons. Since this example uses __dirname (which is part of the node API) in the renderer process, we need to reintroduce it, because it is not available anymore. In this example I use a preload script for this purpose: main.js preload.js preload.js index.html index.html child.html child.html
更多推荐
电子浏览器窗口
发布评论