Saltar al contenido principal

BrowserView

Se puede utilizar un BrowserView para incrustar contenido web adicional dentro de un BrowserWindow. Es como una ventana hija, excepto que su posición es relativa a la de su ventana propietaria. Se puede considerar como una alternativa al tag webview.

Clase: BrowserView

Crear y controlar vistas.

Proceso: principal</0>

Este módulo no puede ser usado hasta que el evento ready del módulo app es emitido.

Ejemplo

/// 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

  • options Object (opcional)

Propiedades de la instancia

Los objetos creados con new BrowserView tienen las siguientes propiedades:

view.webContents Experimental

Un objeto WebContents, que pertenece a esta vista.

Métodos de Instancia

Los objetos creados con new BrowserView tiene los siguientes métodos de instancia:

view.setAutoResize(options) Experimental

  • options Object
    • width boolean (opcional) - Si es true, el ancho de la vista crecerá y se encogerá junto con la ventana. false por defecto.
    • height boolean (opcional) - Si es true, la altura de la vista crecerá y se encogerá junto con la ventana. false por defecto.
    • horizontal boolean (optional) - If true, the view's x position and width will grow and shrink proportionally with the window. false por defecto.
    • vertical boolean (optional) - If true, the view's y position and height will grow and shrink proportionally with the window. false por defecto.

view.setBounds(bounds) Experimental

Redimensiona y mueve la vista a los limites proporcionados en relación a la ventana.

view.getBounds() Experimental

Devuelve Rectangle

Los límites bounds de esta instancia de BrowserView como un Object.

view.setBackgroundColor(color) Experimental

  • color string - Color in Hex, RGB, ARGB, HSL, HSLA or named CSS color format. The alpha channel is optional for the hex type.

Examples of valid color values:

  • Hex
    • #fff (RGB)
    • #ffff (ARGB)
    • #ffffff (RRGGBB)
    • #ffffffff (AARRGGBB)
  • RGB
    • rgb(([\d]+),\s([\d]+),\s([\d]+))
      • e.g. rgb(255, 255, 255)
  • RGBA
    • rgba(([\d]+),\s([\d]+),\s([\d]+),\s*([\d.]+))
      • e.g. rgba(255, 255, 255, 1.0)
  • HSL
    • hsl((-?[\d.]+),\s([\d.]+)%,\s([\d.]+)%)
      • e.g. hsl(200, 20%, 50%)
  • HSLA
    • hsla((-?[\d.]+),\s([\d.]+)%,\s([\d.]+)%,\s*([\d.]+))
      • e.g. hsla(200, 20%, 50%, 0.5)
  • Color name
    • Options are listed in SkParseColor.cpp
    • Similar to CSS Color Module Level 3 keywords, but case-sensitive.
      • e.g. blueviolet or red

Note: Hex format with alpha takes AARRGGBB or ARGB, not RRGGBBA or RGA.