更多例子
在新窗口/选项卡中打开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.cainiaoya.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
尝试一下
打开多个窗口:
window.open("http://www.baidu.com/");
window.open("https://www.cainiaoya.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
尝试一下