BrowserView
History
| Version(s) | Changes |
|---|---|
None | API DEPRECATED |
[!NOTE] The
BrowserViewclass is deprecated, and replaced by the newWebContentsViewclass.
A BrowserView can be used to embed additional web content into a BrowserWindow. 它就像一个子窗口,除了它的位置是相对于父窗口。 这意味着可以替代webview标签.
类: BrowserView
History
| Version(s) | Changes |
|---|---|
None | API DEPRECATED |
创建和控制视图
[!NOTE] The
BrowserViewclass is deprecated, and replaced by the newWebContentsViewclass.
Process: Main
在 app 模块 emitted ready 事件之前,您不能使用此模块。
[!WARNING] Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.
示例
// 在主进程中.
const{ app,BrowserView,BrowserWindow}=require('electron')
app.whenReady().then(()=>{
const win =newBrowserWindow({width:800,height:600})
const view =newBrowserView()
win.setBrowserView(view)
view.setBounds({x:0,y:0,width:300,height:300})
view.webContents.loadURL('https://electronjs.org')
})
new BrowserView([options]) Experimental Deprecated
History
| Version(s) | Changes |
|---|---|
None | API DEPRECATED |
实例属性
使用 new BrowserView 创建的对象具有以下属性:
view.webContents Experimental Deprecated
History
| Version(s) | Changes |
|---|---|
None | API DEPRECATED |
A WebContents object owned by this view.
实例方法
使用 new BrowserView创建的对象具有以下实例方法:
view.setAutoResize(options) Experimental Deprecated
History
| Version(s) | Changes |
|---|---|
None | API DEPRECATED |
None | Standardized auto-resizing behavior across all platforms |
选项对象widthboolean(可选) - 如果为true,视图宽度跟随窗口变化。 默认值为falseheightboolean(可选) - 如果true,视图的高度将增长和缩小 与窗口。 默认值为falsehorizontalboolean (可选) - 如果为true,视图的x轴和宽度将随着窗口的大小变化等比例缩放。 默认值为falseverticalboolean(可选) - 如果true,视图的y位置和高度将增长 和收缩比例与窗口。 默认值为false
view.setBounds(bounds) Experimental Deprecated
History
| Version(s) | Changes |
|---|---|
None | API DEPRECATED |
boundsRectangle
调整视图的大小,并将它移动到窗口边界
view.getBounds() Experimental Deprecated
History
| Version(s) | Changes |
|---|---|
None | API DEPRECATED |
Returns Rectangle
此BrowserView实例的 bounds 为 Object。
view.setBackgroundColor(color) Experimental Deprecated
History
| Version(s) | Changes |
|---|---|
None | API DEPRECATED |
colorstring - 颜色为 Hex,RGB,ARGB,HSL,HSLA 或 命名的CSS颜色的格式。 Hex 的透明通道为可选项。
例如这些有效的 color 值:
- Hex
#fff(RGB)#ffff(ARGB)#ffffff(RRGGBB)#ffffffff(AARRGGBB)
- RGB
rgb\(([\d]+),\s*([\d]+),\s*([\d]+)\)- 例如
rgb(255, 255, 255)
- 例如
- RGBA
rgba\(([\d]+),\s*([\d]+),\s*([\d]+),\s*([\d.]+)\)- 例如
rgba(255, 255, 255, 1.0)
- 例如
- HSL
hsl\((-?[\d.]+),\s*([\d.]+)%,\s*([\d.]+)%\)- 例如
hsl(200, 20%, 50%)
- 例如
- HSLA
hsla\((-?[\d.]+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)- 例如
hsla(200, 20%, 50%, 0.5)
- 例如
- Color name
- 名称列表在 SkParseColor.cpp
- 类似 CSS Color Module Level 3 关键字,但大小写敏感。
- 例如
blueviolet或red。
- 例如
[!NOTE] Hex format with alpha takes
AARRGGBBorARGB, notRRGGBBAAorRGB.