BrowserWindow·续1
-
zoomToPageWidth Boolean (optional) - Controls the behavior on macOS when option-clicking the green stoplight button on the toolbar or by clicking the Window > Zoom menu item. 如果为 true, 窗口将放大到网页的本身宽度, false 将使其缩放到屏幕的宽度。 这也会影响直接调用 maximize() 时的行为。 默认值为 false.
-
tabbingIdentifier String (可选) - 选项组卡的名称,在macOS 10.12+上可使窗口在原生选项卡中打开. 具有相同标识符的窗口将被组合在一起。 这还会在窗口的标签栏中添加一个原生的新选项卡按钮, 并允许 app 和窗口接收 new-window-for-tab 事件。
-
webPreferences Object (optional) - Settings of web page’s features.
-
devTools Boolean (可选) - 是否开启 DevTools. 如果设置为 false, 则无法使用 BrowserWindow.webContents.openDevTools () 打开 DevTools。 默认值为 true。
-
nodeIntegration Boolean (optional) - Whether node integration is enabled. 默认值为 false.
-
nodeIntegrationInWorker Boolean (可选) - 是否在Web工作器中启用了Node集成. 默认值为 false. 更多内容参见 多线程.
-
nodeIntegrationInSubFrames Boolean (可选项)(实验性),是否允许在子页面(iframe)或子窗口(child window)中集成Node.js; 预先加载的脚本会被注入到每一个iframe,你可以用 process.isMainFrame 来判断当前是否处于主框架(main frame)中。
-
preload String (可选) -在页面运行其他脚本之前预先加载指定的脚本 无论页面是否集成Node, 此脚本都可以访问所有Node API 脚本路径为文件的绝对路径。 当 node integration 关闭时, 预加载的脚本将从全局范围重新引入node的全局引用标志 参考示例.
-
sandbox Boolean (可选)-如果设置该参数, 沙箱的渲染器将与窗口关联, 使它与Chromium OS-level 的沙箱兼容, 并禁用 Node. js 引擎。 它与 nodeIntegration 的选项不同,且预加载脚本的 API 也有限制. 更多详情.
-
enableRemoteModule Boolean (optional) - Whether to enable the remote module. 默认值为 true。
-
session Session (可选) - 设置页面的 session 而不是直接忽略 Session 对象, 也可用 partition 选项来代替,它接受一个 partition 字符串. 同时设置了session 和 partition时, session 的优先级更高. 默认使用默认的 session.
-
partition String (optional) - 通过 session 的 partition 字符串来设置界面session. 如果 partition 以 persist:开头, 该页面将使用持续的 session,并在所有页面生效,且使用同一个partition. 如果没有 persist: 前缀, 页面将使用 in-memory session. 通过分配相同的 partition, 多个页可以共享同一会话。 默认使用默认的 session.
-
affinity String (可选) - 当指定,具有相同affinity 的 web页面将在相同的渲染进程运行。 需要注意的是,由于渲染过程中会有代码重用,如 webPreferences的preload, sandbox 和 nodeIntegration等选项会在不同页面之间共用,即使你已经在不同页面中为同一选项设置过不同的值,它们仍会被共用。 因此,建议为affinity相同的页面,使用相同的 webPreferences 这一选项当前是实验性的
-
zoomFactor Number (optional) - The default zoom factor of the page, 3.0 represents 300%. Default is 1.0.
-
javascript Boolean (optional) - Enables JavaScript support. 默认值为 true。
-
webSecurity Boolean (可选) - 当设置为 false, 它将禁用同源策略 (通常用来测试网站), 如果此选项不是由开发者设置的,还会把 allowRunningInsecureContent设置为 true. 默认值为 true。
-
allowRunningInsecureContent Boolean (optional) - Allow an https page to run JavaScript, CSS or plugins from http URLs. 默认值为 false.
-
images Boolean (optional) - Enables image support. 默认值为 true。
-
textAreasAreResizable Boolean (optional) - Make TextArea elements resizable. Default is true.
-
webgl Boolean (optional) - Enables WebGL support. 默认值为 true。
-
plugins Boolean (optional) - Whether plugins should be enabled. 默认值为 false.
-
experimentalFeatures Boolean (optional) - Enables Chromium’s experimental features. 默认值为 false.
-
scrollBounce Boolean (optional) - Enables scroll bounce (rubber banding) effect on macOS. 默认值为 false.
-
enableBlinkFeaturesString(可选) - 以逗号分隔的需要启用的特性列表,譬如CSSVariables,KeyboardEventKey 在 RuntimeEnabledFeatures.json5文件中查看被支持的所有特性.
-
disableBlinkFeatures String (可选) - 以 ,分隔的禁用特性列表, 如 CSSVariables,KeyboardEventKey. 在RuntimeEnabledFeatures.json5 文件中查看被支持的所有特性.
-
defaultFontFamily Object (optional) - Sets the default font for the font-family.
-
standard String (可选) - 默认值为 Times New Roman.
-
serif String (可选) - 默认值为 Times New Roman.
-
sansSerif String (可选) - 默认值为 Arial.
-
monospace String (可选) - 默认值为 Courier New.
-
cursive String (可选) - 默认值为 Script.
-
fantasy String (可选) - 默认值为 Impact.
-
defaultFontSize Integer (可选) - 默认值为 16.
-
defaultMonospaceFontSize Integer (可选) - 默认值为 13.
-
minimumFontSize Integer (可选) - 默认值为 0.
-
defaultEncoding String (可选) - 默认值为 ISO-8859-1.
-
backgroundThrottlingBoolean (可选)-是否在页面成为背景时限制动画和计时器。 这也会影响到 Page Visibility API. 默认值为 true。
-
offscreen Boolean (optional) - 是否绘制和渲染可视区域外的窗口. 默认值为 false. 更多详情, 请参见 offscreen rendering tutorial 。
-
contextIsolation Boolean (可选) - 是否在独立 JavaScript 环境中运行 Electron API和指定的preload 脚本. 默认值为 false. preload脚本的运行环境仍然可以访问document 和 window全局变量,但它将使用自己内置的函数 (如Array, Object, JSON等),并且将被加载的页面与对全局环境所做的任何更改隔离开来. Electron API 仅在 preload 脚本中有效,而不是加载的页面。 在加载可能不受信任的远程内容时, 应使用此选项, 以确保加载的内容不能篡改 preload 脚本和使用的 Electron APIs。 此选项使用 Chrome Content Scripts 使用的相同技术。 通过在控制台选项卡顶部的组合框中选择 “Electron Isolated Context” 条目, 可以在开发工具中访问此上下文。
-
nativeWindowOpen Boolean (可选) - 是否使用原生的window.open(). 默认值为 false. Child windows will always have node integration disabled unless nodeIntegrationInSubFrames is true. 注意: 此选项目前是实验性的。
-
webviewTag Boolean (可选) - 是否启用 <webview> tag标签. 默认值为 false. 注意: 为 < webview> 配置的 preload 脚本在执行时将启用节点集成, 因此应确保远程或不受信任的内容无法创建恶意的 preload 脚本 。 可以使用 webContents 上的 will-attach-webview 事件对 preload 脚本进行剥离, 并验证或更改 <webview> 的初始设置。
-
additionalArguments String[] (可选) - 一系列将会被附加至此app的渲染进程的process.argv的字符串. 对于将少量数据向下传至渲染进程的预加载脚本而言是十分实用的.
-
safeDialogs Boolean (optional) - Whether to enable browser style consecutive dialog protection. 默认值为 false.
-
safeDialogsMessage String (可选) - 当持续对话框保护被触发时显示的消息。 如果没有定义,那么将使用缺省的消息。注意:当前缺省消息是英文,并没有本地化。
-
disableDialogs Boolean (optional) - Whether to disable dialogs completely. Overrides safeDialogs. 默认值为 false.
-
navigateOnDragDrop Boolean (optional) - Whether dragging and dropping a file or link onto the page causes a navigation. 默认值为 false.
-
autoplayPolicy String (optional) - Autoplay policy to apply to content in the window, can be no-user-gesture-required, user-gesture-required, document-user-activation-required. Defaults to no-user-gesture-required.
-
disableHtmlFullscreenWindowResize Boolean (optional) - Whether to prevent the window from resizing when entering HTML Fullscreen. Default is false.
-
accessibleTitle String (optional) - An alternative title string provided only to accessibility tools such as screen readers. This string is not directly visible to users.
-
spellcheck Boolean (optional) - Whether to enable the builtin spellchecker. 默认值为 false.
当使用 minWidth/maxWidth/minHeight/maxHeight 设置最小或最大窗口大小时, 它只限制用户。 它不会阻止您将不符合大小限制的值传递给 setBounds/setSize 或 BrowserWindow 的构造函数。
The possible values and behaviors of the type option are platform dependent. Possible values are:
-
在 Linux 上, 可能的类型有 desktop、dock、toolbar、splash、notification。
-
On macOS, possible types are desktop, textured.
-
textured 类型增加金属色泽的外观 (NSTexturedBackgroundWindowMask).
-
desktop 类型将窗口置于桌面背景级别 (kCGDesktopWindowLevel - 1). 注意,桌面窗口不会接收焦点、键盘或鼠标事件,但您可以使用< 0> globalShortcut < /0 >接收快捷键的消息
-
在 Windows 上, 可能的类型为 toolbar.
实例事件
使用 new BrowserWindow 创建的对象具有以下属性:
注意: 某些事件仅在特定的操作系统上可用, 这些方法会被标记出来。
事件: ‘page-title-updated’
返回:
-
event Event
-
title String
-
explicitSet Boolean
文档更改标题时触发,调用event.preventDefault()将阻止更改标题 explicitSet is false when title is synthesized from file URL.
事件: ‘close’
返回:
- event Event
在窗口要关闭的时候触发。 它在DOM 的beforeunload 和 unload 事件之前触发. 调用event.preventDefault()将阻止这个操作。
通常你想通过 beforeunload处理器来决定是否关闭窗口,但是它也会在窗口重载的时候触发. 在 Electron 里,返回除 undefined之外的任何值都将取消关闭. 例如:
window.onbeforeunload = (e) => { console.log('I do not want to be closed') // 与通常的浏览器不同,会提示给用户一个消息框, //返回非空值将默认取消关闭 //建议使用对话框 API 让用户确认关闭应用程序. e.returnValue = false // 相当于 `return false` ,但是不推荐使用}
注意: window.onbeforeunload = handler 和 window.addEventListener('beforeunload', handler) 的行为有细微的区别。 推荐总是显式地设置 event.returnValue, 而不是仅仅返回一个值, 因为前者在Electron中作用得更为一致.
事件: ‘closed’
Emitted when the window is closed. After you have received this event you should remove the reference to the window and avoid using it any more.
事件: ‘session-end’ Windows
因为强制关机或机器重启或会话注销而导致窗口会话结束时触发
事件: ‘unresponsive’
网页变得未响应时触发
事件: ‘responsive’
未响应的页面变成响应时触发
事件: ‘blur’
当窗口失去焦点时触发
事件: ‘focus’
当窗口获得焦点时触发
事件: ‘show’
当窗口显示时触发
事件: ‘hide’
当窗口隐藏时触发
事件: ‘ready-to-show’
当页面已经渲染完成(但是还没有显示) 并且窗口可以被现实时触发
