此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。
View in English
Always switch to English
Window.close()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
Learn more
See full compatibility
Report feedback
Window.close() 方法关闭当前窗口或某个指定的窗口。
该方法只能由 Window.open() 方法打开的窗口的 window 对象来调用。如果一个窗口不是由脚本打开的,那么,在调用该方法时,JavaScript 控制台会出现类似下面的错误:不能使用脚本关闭一个不是由脚本打开的窗口。 或 Scripts may not close windows that were not opened by script. 。
同时也要注意,对于由 HTMLIFrameElement.contentWindow 返回的 Window 对象,close() 也没有效果。