如何从电子WebContents中获取BrowserWindow?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何从电子WebContents中获取BrowserWindow?相关的知识,希望对你有一定的参考价值。

这可能是我的脸,但给了一个WebContents我如何找到相应的BrowserWindow

在我的头脑中,我能做到

const windows = BrowserWindow.getAllWindows();
const ndx = windows.indexOf(someWebContents);
const window = windows[ndx];

有更简单的方法吗?

答案

这个BrowserWindow静态方法似乎是最直接的方法:

BrowserWindow.fromWebContents(webContents)

返回BrowserWindow - 拥有给定webContents的窗口。

以上是关于如何从电子WebContents中获取BrowserWindow?的主要内容,如果未能解决你的问题,请参考以下文章