如何从电子中的 WebContents 获取 BrowserWindow? [英] How to get a BrowserWindow from a WebContents in electron?
本文介绍了如何从电子中的 WebContents 获取 BrowserWindow?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能让我陷入困境,但给定一个 WebContents
我如何找到相应的 BrowserWindow
?
This is probably stairing me in the face but given a WebContents
how do I find the corresponding BrowserWindow
?
我的头顶我能做到
const windows = BrowserWindow.getAllWindows();
const ndx = windows.indexOf(someWebContents);
const window = windows[ndx];
有没有更简单的方法?
推荐答案
这个 BrowserWindow 静态方法似乎是最直接的方法:
This BrowserWindow static method seems to be the most straightforward way:
BrowserWindow.fromWebContents(webContents)一个>
返回 BrowserWindow - 拥有给定 webContents 的窗口.
Returns BrowserWindow - The window that owns the given webContents.
这篇关于如何从电子中的 WebContents 获取 BrowserWindow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文