JavaScript入門講座

Home > windowオブジェクト > openerプロパティ

openerプロパティ

windowオブジェクトのopenerプロパティはopenメッソドで開かれたウィンドウから元のウィンドウを参照します。

書式window.opener
ブラウザInternet ExplorerFireFoxChromeSafariOpera
openメッソドで開かれたウィンドウから元のウィンドウを参照する
使用例サブウィンドウを開き値を入力後、メインウィンドウのテキストボックスにサブウィンドウの値をセットする。

//-------メイン・ウィンドウ:main.html

<html> 
<head> 
<title>メイン・ウィンドウ</title> 
<script type="text/javascript"> 
	function wOpen(page) {
		window.open(page,'new','');
	}
</script>
</head>
<body>
<form>
入力値:
<input type="text" id="txtMain">
<input type="button" value="サブ画面表示" onclick="wOpen('sub.html');">
</form>
</body>
</html> 

//-------サブ・ウィンドウ:sub.html

<html> 
<head> 
<title>サブ・ウィンドウ</title> 
<script type="text/JavaScript"> 
function setValue(){
	var str = document.getElementById("txtSub").value;
	window.opener.document.getElementById("txtMain").value = str;
	self.close();
}
</script>
<body>
<form>
入力値:<input type="text" id="txtSub">
<input type="button" value="メイン画面にセット" onclick="setValue();">
</form>
</body>
</html> 
						
関連メンバ
nameウィンドウ名
self現在のウィンドウ自身
top1番手前にあるウィンドウを返します
closedウィンドウが閉じられている状態