Window opener 屬性

定義和用法
opener 屬性是一個可讀可寫的屬性,可返回對創建該窗口的 Window 對象的引用。
當使用window.open()打開一個窗口,您可以使用此屬性返回來自目標窗口源(父)窗口的詳細資訊。
代碼提示: window.opener.close()將關閉源(父)窗口。
語法
window.opener
流覽器支持
所有主要流覽器都支持 opener 屬性
實例
實例
向opener窗口寫文本(父窗口):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function openWin(){
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>這是我的窗口</p>");
myWindow.focus();
myWindow.opener.document.write("<p>這個是源窗口!</p>");
}
</script>
</head>
<body>
<input type="button" value="打開我的窗口" onclick="openWin()" />
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function openWin(){
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>這是我的窗口</p>");
myWindow.focus();
myWindow.opener.document.write("<p>這個是源窗口!</p>");
}
</script>
</head>
<body>
<input type="button" value="打開我的窗口" onclick="openWin()" />
</body>
</html>
