Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Window: close() method

BaselineWidely available

TheWindow.close() method closes the current window, orthe window on which it was called.

This method can only be called on windows that were opened by a script using theWindow.open() method, or on top-level windows that have a single history entry. If the window doesn't match these requirements, an errorsimilar to this one appears in the console:Scripts may not close windows that were not opened by script.

Note also thatclose() has no effect when called onWindowobjects returned byHTMLIFrameElement.contentWindow.

Syntax

js
close()

Parameters

None.

Return value

None (undefined).

Examples

Closing a window opened withwindow.open()

This example shows a method which opens a window and a second one which closes thewindow; this demonstrates how to useWindow.close() to close a windowopened by callingwindow.open().

js
// Global variable to store a reference to the opened windowlet openedWindow;function openWindow() {  openedWindow = window.open("more-info.htm");}function closeOpenedWindow() {  openedWindow.close();}

Specifications

Specification
HTML
# dom-window-close-dev

Browser compatibility

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp