Window openerプロパティ
Window オブジェクト
定義と使用方法
opener プロパティは読み書き可能なプロパティで、そのウィンドウを作成した Window オブジェクトへの参照を返します。
window.open() でウィンドウを開く場合、このプロパティを使用して、ターゲットウィンドウのソース(親)ウィンドウの詳細情報を取得できます。
コードヒント:window.opener.close() はソース(親)ウィンドウを閉じます。
構文
window.opener
ブラウザサポート
![]()
![]()
![]()
![]()
![]()
すべての主要ブラウザが opener プロパティをサポートしています
例
例
opener ウィンドウ(親ウィンドウ)にテキストを書き込む:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.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>サンプル(example.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>
試してみる »
Window オブジェクト その他の拡張