Window.resizeTo
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
概述
动态调整窗口的大小。
语法
window.resizeTo(aWidth, aHeight)
参数
aWidth
是一个整数,表示新的outerWidth
(单位:像素)(包括滚动条、窗口边框等)。aHeight
是一个整数,表示新的outerHeight
(单位:像素)(包括滚动条、标题栏、窗口边框等)。
示例
js
// 将窗口设置为整个屏幕的 1/4 大小(面积)
function quarter() {
window.resizeTo(window.screen.availWidth / 2, window.screen.availHeight / 2);
}
备注
从 Firefox 7 开始,不能改变浏览器窗口的大小了,要依据下面的规则:
- 不能设置那些不是通过 window.open 创建的窗口或 Tab 的大小。
- 当一个窗口里面含有一个以上的 Tab 时,无法设置窗口的大小。
规范
Specification |
---|
CSSOM View Module # dom-window-resizeto |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
resizeTo |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.