openerプロパティ
windowオブジェクトのopenerプロパティはopenメッソドで開かれたウィンドウから元のウィンドウを参照します。
書式 | window.opener | |
---|---|---|
ブラウザ | ||
値 | 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 | 現在のウィンドウ自身 |
top | 1番手前にあるウィンドウを返します |
closed | ウィンドウが閉じられている状態 |