BrowserView
A BrowserView
can be used to embed additional web content into a BrowserWindow. BrowserView
可用于将其他web内容嵌入到BrowserWindow中。It is like a child window, except that it is positioned relative to its owning window. 它就像一个子窗口,只是它是相对于其所属窗口定位的。It is meant to be an alternative to the 它是用来替代webview
tag.webview
标记的。
Class: BrowserView
Create and control views.创建和控制视图。
Process: 进程:Main
This module cannot be used until the 在发出ready
event of the app
module is emitted.app
模块的ready
事件之前,无法使用此模块。
Example示例
// In the main process.
const { app, BrowserView, BrowserWindow } = require('electron')
app.whenReady().then(() => {
const win = new BrowserWindow({ width: 800, height: 600 })
const view = new BrowserView()
win.setBrowserView(view)
view.setBounds({ x: 0, y: 0, width: 300, height: 300 })
view.webContents.loadURL('https://electronjs.org')
})
new BrowserView([options])
Experimental
Instance Properties实例属性
Objects created with 使用new BrowserView
have the following properties:new BrowserView
创建的对象具有以下属性:
view.webContents
Experimental
A WebContents object owned by this view.此视图所拥有的WebContents对象。
Instance Methods实例方法
Objects created with 使用new BrowserView
have the following instance methods:new BrowserView
创建的对象具有以下实例方法:
view.setAutoResize(options)
Experimental
view.setBounds(bounds)
Experimental
bounds
Rectangle
Resizes and moves the view to the supplied bounds relative to the window.调整视图的大小并将其移动到相对于窗口提供的边界。
view.getBounds()
Experimental
Returns 返回Rectangle
The 此BrowserView实例作为bounds
of this BrowserView instance as Object
.Object
形式的的bounds
。
view.setBackgroundColor(color)
Experimental
color
string -Color in Hex, RGB, ARGB, HSL, HSLA or named CSS color format.颜色采用十六进制、RGB、ARGB、HSL、HSLA或命名的CSS颜色格式。The alpha channel is optional for the hex type.对于十六进制类型,alpha通道是可选的。
Examples of valid 有效color
values:color
值示例:
- Hex
#fff
(RGB)#ffff
(ARGB)#ffffff
(RRGGBB)#ffffffff
(AARRGGBB)
- RGB
rgb(([\d]+),\s([\d]+),\s([\d]+))
- e.g.
rgb(255, 255, 255)
- e.g.
- RGBA
rgba(([\d]+),\s([\d]+),\s([\d]+),\s*([\d.]+))
- e.g.
rgba(255, 255, 255, 1.0)
- e.g.
- HSL
hsl((-?[\d.]+),\s([\d.]+)%,\s([\d.]+)%)
- e.g.
hsl(200, 20%, 50%)
- e.g.
- HSLA
hsla((-?[\d.]+),\s([\d.]+)%,\s([\d.]+)%,\s*([\d.]+))
- e.g.
hsla(200, 20%, 50%, 0.5)
- e.g.
Color name颜色名称Options are listed in SkParseColor.cppSkParseColor.cpp中列出了选项Similar to CSS Color Module Level 3 keywords, but case-sensitive.类似于CSS颜色模块级别3关键字,但区分大小写。- e.g.
blueviolet
orred
- e.g.
Note: Hex format with alpha takes 带alpha的十六进制格式采用AARRGGBB
or ARGB
, not RRGGBBA
or RGA
.AARGGBB
或ARGB
,而不是RRGGBBA
或RGA
。