WebContentsView
一个用来显示网页内容的视图类。
进程: 主进程
app 模块出发 ready 事件之后方可使用这个模块。
const { BaseWindow, WebContentsView } = require('electron')
const win = new BaseWindow({ width: 800, height: 400 })
const view1 = new WebContentsView()
win.contentView.addChildView(view1)
view1.webContents.loadURL('https://electronjs.org')
view1.setBounds({ x: 0, y: 0, width: 400, height: 400 })
const view2 = new WebContentsView()
win.contentView.addChildView(view2)
view2.webContents.loadURL('https://github.com/electron/electron')
view2.setBounds({ x: 400, y: 0, width: 400, height: 400 })
Class: WebContentsView 继承自 View
一个用来显示网页内容的视图类。
进程: 主进程
WebContentsView 继承自 View。
WebContentsView 是一个 EventEmitter。
警告
Electron 的内置类,不能被继承。 更多信息可以查看 常见问答。
new WebContentsView([options])
创建一个 WebContentsView。
实例属性
使用 new WebContentsView 创建的对象具有以下属性,此外还包括从 View 继承的属性:
view.webContents Readonly
一个 WebContents 属性,包含对当前显示的 WebContents 的引用。
使用此属性与 WebContents 进行交互,例如加载 URL。
const { WebContentsView } = require('electron')
const view = new WebContentsView()
view.webContents.loadURL('https://electronjs.org/')