这个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: Bugs Chromium Issue 1164959. |
对新窗口的引用,或无效的如果通话失败。 |
打开一个名为 "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.91xjr.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
亲自试一试 »
打开一个新窗口。使用 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 | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!