- BrowserWindow·续3
- win.blur()
- win.isFocused()
- win.isDestroyed()
- win.show()
- win.showInactive()
- win.hide()
- win.isVisible()
- win.isModal()
- win.maximize()
- win.unmaximize()
- win.isMaximized()
- win.minimize()
- win.restore()
- win.isMinimized()
- win.setFullScreen(flag)
- win.isFullScreen()
- win.setSimpleFullScreen(flag) macOS
- win.isSimpleFullScreen() macOS
- win.isNormal()
- win.setAspectRatio(aspectRatio[, extraSize]) macOS
- win.setBackgroundColor(backgroundColor)
- win.previewFile(path[, displayName]) macOS
- win.closeFilePreview() macOS
- win.setBounds(bounds[, animate])
- win.getBounds()
- win.setContentBounds(bounds[, animate])
- win.getContentBounds()
- win.getNormalBounds()
- win.setEnabled(enable)
- win.isEnabled()
- win.setSize(width, height[, animate])
- win.getSize()
- win.setContentSize(width, height[, animate])
- win.getContentSize()
- win.setMinimumSize(width, height)
- win.getMinimumSize()
- win.setMaximumSize(width, height)
- win.getMaximumSize()
- win.setResizable(resizable)
- win.isResizable()
- win.setMovable(movable) macOS Windows
- win.isMovable() macOS Windows
- win.setMinimizable(minimizable) macOS Windows
- win.isMinimizable() macOS Windows
- win.setMaximizable(maximizable) macOS Windows
- win.isMaximizable() macOS Windows
- win.setFullScreenable(fullscreenable)
- win.isFullScreenable()
- win.setClosable(closable) macOS Windows
- win.isClosable() macOS Windows
- win.setAlwaysOnTop(flag[, level][, relativeLevel])
- win.isAlwaysOnTop()
- win.moveAbove(mediaSourceId)
- win.moveTop()
- win.center()
- win.setPosition(x, y[, animate])
- win.getPosition()
- win.setTitle(title)
- win.getTitle()
- win.setSheetOffset(offsetY[, offsetX]) macOS
- win.flashFrame(flag)
- win.setSkipTaskbar(skip)
- win.setKiosk(flag)
- win.isKiosk()
- win.getMediaSourceId()
BrowserWindow·续3
win.blur()
取消窗口的聚焦
win.isFocused()
返回 Boolean - 判断窗口是否聚焦
win.isDestroyed()
返回 Boolean -判断窗口是否被销毁
win.show()
显示并聚焦于窗口
win.showInactive()
显示但不聚焦于窗口
win.hide()
隐藏窗口
win.isVisible()
返回 Boolean - 判断窗口是否可见
win.isModal()
返回 Boolean - 判断是否为模态窗口
win.maximize()
Maximizes the window. This will also show (but not focus) the window if it isn’t being displayed already.
win.unmaximize()
取消窗口最大化
win.isMaximized()
返回 Boolean - 判断窗口是否最大化
win.minimize()
Minimizes the window. On some platforms the minimized window will be shown in the Dock.
win.restore()
将窗口从最小化状态恢复到以前的状态。
win.isMinimized()
返回 Boolean -判断窗口是否最小化
win.setFullScreen(flag)
- flag Boolean
设置窗口是否应处于全屏模式。
win.isFullScreen()
返回 Boolean - 窗口当前是否已全屏
win.setSimpleFullScreen(flag) macOS
- flag Boolean
进入或离开简单的全屏模式。
简单全屏模式模拟 Mac OS X prior to Lion (10.7) 版本中发现的原生全屏行为。
win.isSimpleFullScreen() macOS
返回 Boolean - 窗口是否为简单全屏模式(pre-Lion)。
win.isNormal()
返回 Boolean - 窗口是否处于正常状态(未最大化,未最小化,不在全屏模式下)。
win.setAspectRatio(aspectRatio[, extraSize]) macOS
-
aspectRatio Float- 为内容视图保持的宽高比.
-
extraSize Size (optional) - The extra size not to be included while maintaining the aspect ratio.
这将使窗口保持长宽比。 额外的大小允许开发人员有空间 (以像素为单位), 不包括在纵横比计算中。 此 API 已经考虑了窗口大小和内容大小之间的差异。
想象一个使用高清视频播放器和相关控件的普通窗口。 假假如左边缘有15px, 右边缘有25px, 在播放器下面有50px. 为了保持16:9 的长宽比 (标准的HD长宽比为1920x1080), 我们可以调用这个api传入参数16/9 和[ 40,50 ]. 第二个参数不管网页中的额外的宽度和高度在什么位置, 只要它们存在就行. 在全部内部窗口中,加上任何额外的宽度和高度 。
使用 0 调用此函数,将会移除先前设置的宽高比。
win.setBackgroundColor(backgroundColor)
- backgroundColor String - 十六进制的窗口背景色,如 #66CD00、#FFF和#80FFFFFF。 (如果transparent是true的话,也支持alpha 通道。) 默认值为 #FFF(白色)。
Sets the background color of the window. See Setting backgroundColor.
win.previewFile(path[, displayName]) macOS
-
path String -要用 QuickLook 预览的文件的绝对路径。 这一点很重要,因为Quick Look 使用了路径上的文件名和文件扩展名 来决定要打开的文件的内容类型。
-
displayName String (可选) - 在Quick Look 模态视图中显示的文件的名称。 这完全是视觉的,不会影响文件的内容类型。 默认值为 path.
使用 Quick Look来预览路径中的文件.
win.closeFilePreview() macOS
关闭当前打开的 Quick Look 面板.
win.setBounds(bounds[, animate])
-
bounds Partial<Rectangle>
-
animate Boolean (可选) macOS
重置窗口,并且移动窗口到指定的位置. Any properties that are not supplied will default to their current values.
const { BrowserWindow } = require('electron')const win = new BrowserWindow()// set all bounds propertieswin.setBounds({ x: 440, y: 225, width: 800, height: 600 })// set a single bounds propertywin.setBounds({ width: 100 })// { x: 440, y: 225, width: 100, height: 600 }console.log(win.getBounds())
win.getBounds()
Returns Rectangle - The bounds of the window as Object.
win.setContentBounds(bounds[, animate])
-
bounds Rectangle
-
animate Boolean (可选) macOS
调整窗口的工作区 (如网页) 的大小并将其移动到所提供的边界。
win.getContentBounds()
Returns Rectangle - The bounds of the window’s client area as Object.
win.getNormalBounds()
返回 Rectangle - 包含正常状态下的窗口大小。
注意:无论当前的窗口状态为:最大化、最小化或者全屏,这个方法都将得到窗口在正常显示状态下的位置信息以及大小信息。 在正常状态下,getBounds 与 getNormalBounds 得到的边界信息 Rectangle 是一致的。
win.setEnabled(enable)
- enable Boolean
禁用或者启用窗口。
win.isEnabled()
Returns Boolean - whether the window is enabled.
win.setSize(width, height[, animate])
-
width Integer
-
height Integer
-
animate Boolean (可选) macOS
调整窗口的width和 height. If width or height are below any set minimum size constraints the window will snap to its minimum size.
win.getSize()
返回 Integer []-包含窗口的宽度和高度。
win.setContentSize(width, height[, animate])
-
width Integer
-
height Integer
-
animate Boolean (可选) macOS
将窗口的工作区 (如网页) 的大小调整为 width 和 height。
win.getContentSize()
返回 Integer []-包含窗口的宽度和高度。
win.setMinimumSize(width, height)
-
width Integer
-
height Integer
设置窗口最小化的 width 和height.
win.getMinimumSize()
返回 Integer []-包含窗口最小化的宽度和高度。
win.setMaximumSize(width, height)
-
width Integer
-
height Integer
设置窗口最大化的 width 和 height.
win.getMaximumSize()
返回 Integer []-包含窗口最大化的宽度和高度。
win.setResizable(resizable)
- resizable Boolean
设置用户是否可以手动调整窗口大小。
过时的
win.isResizable()
返回 Boolean - 设置窗口是否可以被用户改变大小.
过时的
win.setMovable(movable) macOS Windows
- movable Boolean
Sets whether the window can be moved by user. On Linux does nothing.
过时的
win.isMovable() macOS Windows
返回 Boolean - 窗口是否可以被用户拖动
在 Linux 上总是返回 true。
过时的
win.setMinimizable(minimizable) macOS Windows
- minimizable Boolean
Sets whether the window can be manually minimized by user. On Linux does nothing.
过时的
win.isMinimizable() macOS Windows
返回 Boolean -窗口是否可以最小化
在 Linux 上总是返回 true。
过时的
win.setMaximizable(maximizable) macOS Windows
- maximizable Boolean
Sets whether the window can be manually maximized by user. On Linux does nothing.
过时的
win.isMaximizable() macOS Windows
返回 Boolean - 窗口是否可以最大化.
在 Linux 上总是返回 true。
过时的
win.setFullScreenable(fullscreenable)
- fullscreenable Boolean
设置点击最大化按钮是否可以全屏或最大化窗口.
过时的
win.isFullScreenable()
返回 Boolean - 是否为全屏状态或窗口最大化
过时的
win.setClosable(closable) macOS Windows
- closable Boolean
Sets whether the window can be manually closed by user. On Linux does nothing.
过时的
win.isClosable() macOS Windows
返回 Boolean - 窗口是否可以被用户关闭.
在 Linux 上总是返回 true。
过时的
win.setAlwaysOnTop(flag[, level][, relativeLevel])
-
flag Boolean
-
level String (optional) macOS Windows - Values include normal, floating, torn-off-menu, modal-panel, main-menu, status, pop-up-menu, screen-saver, and dock (Deprecated). The default is floating when flag is true. The level is reset to normal when the flag is false. Note that from floating to status included, the window is placed below the Dock on macOS and below the taskbar on Windows. From pop-up-menu to a higher it is shown above the Dock on macOS and above the taskbar on Windows. See the macOS docs for more details.
-
relativeLevel Integer (可选) macOS - 设置此窗口相对于给定 级别的层数。. 默认值为0. 请注意, Apple 不鼓励在 屏幕保护程序 之上设置高于1的级别。
Sets whether the window should show always on top of other windows. After setting this, the window is still a normal window, not a toolbox window which can not be focused on.
win.isAlwaysOnTop()
返回 Boolean - 当前窗口是否始终在其它窗口之前.
win.moveAbove(mediaSourceId)
- mediaSourceId String - Window id in the format of DesktopCapturerSource’s id. For example “window:1869:0”.
Moves window above the source window in the sense of z-order. If the mediaSourceId is not of type window or if the window does not exist then this method throws an error.
win.moveTop()
无论焦点如何, 将窗口移至顶端(z轴上的顺序).
win.center()
将窗口移动到屏幕中央。
win.setPosition(x, y[, animate])
-
x Integer
-
y Integer
-
animate Boolean (可选) macOS
将窗口移动到 x 和 y。
win.getPosition()
返回 Integer[] - 返回一个包含当前窗口位置的数组.
win.setTitle(title)
- title String
将原生窗口的标题更改为 title。
win.getTitle()
返回 String-原生窗口的标题。
Note: The title of the web page can be different from the title of the native window.
win.setSheetOffset(offsetY[, offsetX]) macOS
-
offsetY Float
-
offsetX Float (可选)
Changes the attachment point for sheets on macOS. By default, sheets are attached just below the window frame, but you may want to display them beneath a HTML-rendered toolbar. 例如:
const { BrowserWindow } = require('electron')let win = new BrowserWindow()let toolbarRect = document.getElementById('toolbar').getBoundingClientRect()win.setSheetOffset(toolbarRect.height)
win.flashFrame(flag)
- flag Boolean
启动或停止闪烁窗口, 以吸引用户的注意。
win.setSkipTaskbar(skip)
- skip Boolean
使窗口不显示在任务栏中。
win.setKiosk(flag)
- flag Boolean
进入或离开 kiosk 模式。
win.isKiosk()
返回 Boolean - 判断窗口是否处于kiosk模式.
win.getMediaSourceId()
Returns String - Window id in the format of DesktopCapturerSource’s id. For example “window:1234:0”.
