Window open() method

Ufafanuzi na matumizi

open() Tukio hilo hupunguza nyofu mpya kwenye mifumo wa kusaidia hali hilo, kama inasababisha kwa sababu ya mifano ya mifumo wa kusaidia hali hilo na thamani za kina.

Tazama pia:

close() method

Mfano

Mfano 1

Inafungua "www.codew3c.com" kwenye tab kipya kwenye mifumo wa kusaidia hali hilo mpya:

window.open("https://www.codew3c.com");

Kuomba kwenye kesi yako

Mfano mengi inapatikana kwenye ukurasa chini.

Inasababisha

window.open(url, name, features, parameter, used to declare whether the new document has its own entry in the window's browsing history or replaces the current document's entry. If)

Tukio hilo

Tukio hilo 描述
url

Inahofu. URL ya ukurasa unaopewa.

Hakupewa. url, itakuwa na nyofu mapya kwenye nyofu mapya au tab kipya.

name Inahofu. Kina ya target au jina la nyofu.
features Inahofu. Orodha ya matumizi yenye majina ya kiwango kipya, kama jumuiya ya viwango vya kiwango, bila mawingu.
parameter, used to declare whether the new document has its own entry in the window's browsing history or replaces the current document's entry. If

Inakataliwa.

Inasababisha URL inatokana na orodha ya historia kwa kujinga kipya au kusaidia hali hilo

Inasababisha thamani zifuatavyo:

  • true - URL inasaidia kusaidia historia kwa kusaidia hali hilo
  • false - URL inatokana na orodha ya historia kwa kujinga kipya

Tahakika:Chrome inakusaidia parameter, used to declare whether the new document has its own entry in the window's browsing history or replaces the current document's entry. If Hakikiano kuzingatia tukio hilo kwa kusababisha kosa.

Tukio hilo huzungumza na thamani zifuatavyo:

描述
_blank URL inawakilika kwenye nyofu mapya au tab kipya. Mtu wa kawaida.
_parent URL inawakilika kwenye mfumo wa kina.
_self URL inasifanya kusaidia hali hilo.
_top URL 替换任何可能加载的框架集。
name 窗口的名称(不指定窗口的标题)。

features 参数支持以下值:

描述
fullscreen=yes|no|1|0 是否以全屏模式显示浏览器。默认为否。全屏模式的窗口也必须处于影院模式。仅限 IE。
height=pixels 窗口的高度,以像素计。最小值为 100。
left=pixels 窗口的左侧位置(X 坐标),以像素计。不允许负值。
location=yes|no|1|0 是否显示地址字段。仅限 Opera。
menubar=yes|no|1|0 是否显示菜单栏。
resizable=yes|no|1|0 窗口是否可调整大小。仅限 IE。
scrollbars=yes|no|1|0 是否显示滚动条。仅限 IE、Firefox 和 Opera。
status=yes|no|1|0 是否添加状态栏。
titlebar=yes|no|1|0 是否显示标题栏。除非调用的应用程序是 HTML 应用程序或受信任的对话框,否则将被忽略。
toolbar=yes|no|1|0 是否显示浏览器工具栏。仅限 IE 和 Firefox。
top=pixels 窗口的顶部位置(Y 坐标),以像素计。不允许负值。
width=pixels 窗口的宽度,以像素计。最小值为 100。

返回值

对新窗口的引用,如果调用失败,则为 null。

技术细节

说明

open() 方法将查找已经存在的窗口或者打开新的浏览器窗口。如果 name 参数指定了已经存在的窗口,则返回对该窗口的引用。返回的窗口将显示 url 参数指定的文档,但忽略 features 参数。在只知道窗口名称的情况下,这是 JavaScript 获得对那个窗口引用的唯一方式。

如果没有指定 name 参数,或者它指定的窗口不存在,那么 open() 方法将创建新的浏览器窗口。这个新窗口将显示 url 参数指定的 URL,它的名称由 name 指定,大小以及控件由 features 参数指定。如果 url 是空串,那么 open() 将打开新窗口。

name 参数指定新窗口的名称。这个名称中只能够出现数字、字母或下划线。它可以作为标记 的 target 属性的值,用来迫使文档在这个指定的窗口中显示。

当使用方法 Window.open() 给已有的指定窗口装载新文档时,可以给它传递 parameter, used to declare whether the new document has its own entry in the window's browsing history or replaces the current document's entry. If 参数,用来声明新文档是在窗口的浏览历史中拥有自己的条目,还是替换当前文档的条目。如果 parameter, used to declare whether the new document has its own entry in the window's browsing history or replaces the current document's entry. If replace If the value is true, the new document will replace the old document. If the value is false, or omitted, then the new document will have its own entry in the window's browsing history. The function provided by this parameter is similar to Location.replace() method

Please do not confuse Window.open() methods are very similar to the features provided by Document.open() method, to make your code clear, it is best to use Window.open(), and do not use open(). In the event handler defined as an HTML attribute, the function open() is usually interpreted as Document.open(), so in this case, you must use Window.open().

Window features

features is a list of features to be displayed in the window, separated by commas. If the value of this optional parameter is empty or it is omitted, the window will display all features. However, if features specified a feature, then the features that do not appear in this list will not be displayed in the window. It should be noted that this string does not contain any spaces or whitespace, and the format of each element is as follows:

feature[=value]

For most features,value The value is yes or no. The equal sign and value The values can be omitted, and if the feature appears, it is assumed that its value The value is yes, and if it does not appear, it is assumed value The value is no. However, the width or height value The value is required, and you must specify their pixel values.

Masharti ya vifaa vya kurejea interneti

Wote wengi wa vifaa vya kurejea interneti wamekuwa na masharti open():

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Masharti Masharti Masharti Masharti Masharti Masharti

Mfano zaidi

Mfano 2

Fungua ukurasa about:blank katika sikupeo/kitabu cha chaguo kwa uwanja mpya:

var myWindow = window.open("", "", "width=200,height=100");

Kuomba kwenye kesi yako

Mfano 3

Fungua sikupeo mpya kina jina "MsgWindow" na kusoma matukio yoyote kwenye sikupeo hii:

var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");

Kuomba kwenye kesi yako

Mfano 4

Kifungua sikupeo mpya inayotumiwa kwa sikupeo hii:

var myWindow = window.open("", "_self");
myWindow.document.write("<p>Nimekubadilisha kijana hii.</p>")

Kuomba kwenye kesi yako

Mfano 5

Kuwahusisha kijana kuzingatia kwa kusimamia ukirika wako:

window.open("https://www.codew3c.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");

Kuomba kwenye kesi yako

Mfano 6

Kuwahusisha chanzo mbalimbali:

window.open("http://www.google.com/");
window.open("https://www.codew3c.com/");

Kuomba kwenye kesi yako

Mfano 7

Kuwahusisha kijana kuzingatia. Kisha tumia close() kufunga kijana kuzingatia hii:

function openWin() {
  myWindow = window.open("", "myWindow", "width=200,height=100");   // Kuwahusisha kijana kuzingatia
}
function closeWin() {
  myWindow.close();   // Kufunga kijana kuzingatia hii
}

Kuomba kwenye kesi yako

Mfano 8

Kuwahusisha kijana kuzingatia. Tumia kina ya name kuhakikisha jina la kijana kuzingatia:

var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>Jina la kijana hii ni: " + myWindow.name + "</p>");

Kuomba kwenye kesi yako

Mfano 9

Tumia kina ya opener kuhakikisha kuzingatia kwa kuzingatia kuzingatia kuzingatia kwa ujenzi

var myWindow = window.open("", "myWindow", "width=200,height=100");   // Kuwahusisha kijana kuzingatia
myWindow.document.write("<p>Ini ni 'myWindow'</p>");   // Ujenzi wa kijana kuzingatia
myWindow.opener.document.write("<p>Ini kijana ni msingi wa kuzingatia!</p>");  // Kuzingatia ukingo mpya wa kuzingatia kwa uandikwa wa ujenzi

Kuomba kwenye kesi yako