창 열기()
실시예 1
새 브라우저 탭에서 "www.w3schools.com"을 엽니다.
window.open("https://www.w3schools.com");
아래에 더 많은 예가 있습니다.
정의 및 사용
이 open()
메서드는 브라우저 설정 및 매개변수 값에 따라 새 브라우저 창 또는 새 탭을 엽니다.
또한보십시오:
통사론
window.open(URL, name, specs, replace)
매개변수
Parameter | Description | ||||||||||||||||||||||||
URL | Optional. The URL of the page to open. If no URL is specified, a new blank window/tab is opened |
||||||||||||||||||||||||
name | Optional. The target attribute or the name of the window. The following values are supported: | ||||||||||||||||||||||||
|
|||||||||||||||||||||||||
specs | Optional. A comma-separated list of items, no whitespaces. The following values are supported: | ||||||||||||||||||||||||
| |||||||||||||||||||||||||
replace |
DeprecatedSpecifies whether the URL creates a new entry or replaces the current entry in the history list. The following values are supported:
WarningChrome throws an exception when using this parameter. Source: . |
반환 값
새 창에 대한 참조이거나 호출이 실패한 경우 null 입니다. |
더 많은 예
새 창/탭에서 about:blank 페이지 열기:
var myWindow = window.open("", "", "width=200,height=100");
"MsgWindow"라는 새 창을 열고 텍스트를 작성하십시오.
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");
현재 창을 새 창으로 교체:
var myWindow = window.open("", "_self");
myWindow.document.write("<p>I replaced the current window.</p>");
새 창을 열고 모양을 제어합니다.
window.open("https://www.w3schools.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
여러 탭 열기:
window.open("http://www.google.com/");
window.open("https://www.w3schools.com/");
새 창을 엽니다. close()를 사용하여 새 창을 닫습니다.
function openWin() {
myWindow = window.open("", "myWindow", "width=200,height=100"); // Opens a new window
}
function closeWin() {
myWindow.close(); // Closes the new window
}
새 창을 엽니다. name 속성을 사용하여 새 창의 이름을 반환합니다.
var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This window's name is: " + myWindow.name + "</p>");
opener 속성을 사용하여 새 창을 만든 창에 대한 참조 반환:
var myWindow = window.open("", "myWindow", "width=200,height=100"); // Opens a new window
myWindow.document.write("<p>This is 'myWindow'</p>"); // Text in the new window
myWindow.opener.document.write("<p>This is the source window!</p>"); // Text in the window that created the new window
브라우저 지원
open()
모든 브라우저에서 지원됩니다:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |