Window opener 屬性

2020-08-12 16:26 更新

Window opener 屬性

Window 對(duì)象參考手冊(cè)Window 對(duì)象

定義和用法

opener 屬性是一個(gè)可讀可寫的屬性,可返回對(duì)創(chuàng)建該窗口的 Window 對(duì)象的引用。

當(dāng)使用window.open()打開一個(gè)窗口,您可以使用此屬性返回來自目標(biāo)窗口源(父)窗口的詳細(xì)信息。

代碼提示: window.opener.close()將關(guān)閉源(父)窗口。

語法

window.opener

屬性

屬性 描述
alert alert()
blur blur()
clearinterval clearInterval()
cleartimeout clearTimeout()
close close()
confirm confirm()
createpopup createPopup()
focus focus()
moveby moveBy()
moveto moveTo()
open open()
print print()
prompt prompt()
resizeby resizeBy()
resizeto resizeTo()
scrollby scrollBy()
scrollto scrollTo()
setinterval setInterval()
settimeout setTimeout()

瀏覽器支持

Internet Explorer Firefox Opera Google Chrome Safari

所有主要瀏覽器都支持 opener 屬性


實(shí)例

實(shí)例

向opener窗口寫文本(父窗口):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool教程(w3cschool.cn)</title>
<script>
function openWin(){
    myWindow=window.open('','','width=200,height=100');
    myWindow.document.write("<p>這是我的窗口</p>");
    myWindow.focus();
    myWindow.opener.document.write("<p>這個(gè)是源窗口!</p>");
}
</script>
</head>
<body>

<input type="button" value="打開我的窗口" onclick="openWin()" />

</body>
</html>

嘗試一下 ?


Window 對(duì)象參考手冊(cè)Window 對(duì)象


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)