Window opener 屬性

定義和用法
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() | |
prompt | prompt() |
resizeby | resizeBy() |
resizeto | resizeTo() |
scrollby | scrollBy() |
scrollto | scrollTo() |
setinterval | setInterval() |
settimeout | setTimeout() |
瀏覽器支持
所有主要瀏覽器都支持 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>
<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>
嘗試一下 ?

更多建議: