回答編集履歴
1
コードの記述を削除しました。
test
CHANGED
@@ -1,121 +1,3 @@
|
|
1
|
-
|
1
|
+
回答者のお答えの中で正解ではないようなので、
|
2
2
|
|
3
|
-
localstorageを使ったサンプルコードです。
|
4
|
-
|
5
|
-
parent.html
|
6
|
-
|
7
|
-
```
|
8
|
-
|
9
|
-
<!DOCTYPE html>
|
10
|
-
|
11
|
-
<html lang="ja">
|
12
|
-
|
13
|
-
<head>
|
14
|
-
|
15
|
-
<meta charset="utf-8">
|
16
|
-
|
17
|
-
|
3
|
+
コードの記述を削除しました。
|
18
|
-
|
19
|
-
// 子ウィンドウを開く
|
20
|
-
|
21
|
-
function openWindow() {
|
22
|
-
|
23
|
-
window.open('child.html', 'child', 'width=500,height=250')
|
24
|
-
|
25
|
-
}
|
26
|
-
|
27
|
-
//フォーカスがテキストボックスに当たった時
|
28
|
-
|
29
|
-
function focusWindow() {
|
30
|
-
|
31
|
-
var txt = localStorage.getItem("inputText");
|
32
|
-
|
33
|
-
document.getElementById("inputText").value = txt;
|
34
|
-
|
35
|
-
localStorage.clear();
|
36
|
-
|
37
|
-
}
|
38
|
-
|
39
|
-
</script>
|
40
|
-
|
41
|
-
</head>
|
42
|
-
|
43
|
-
<body>
|
44
|
-
|
45
|
-
<form name="parentfrm" action="" method="post">
|
46
|
-
|
47
|
-
<input type="text" id="inputText" class="form-control" name="parent_input" value="" placeholder="ここに値がセットされます。" onFocus="focusWindow()">
|
48
|
-
|
49
|
-
</form>
|
50
|
-
|
51
|
-
<a href="" onClick="openWindow()">子画面を開く</a>
|
52
|
-
|
53
|
-
</body>
|
54
|
-
|
55
|
-
</html>
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
```
|
60
|
-
|
61
|
-
child.html
|
62
|
-
|
63
|
-
```
|
64
|
-
|
65
|
-
<!DOCTYPE html>
|
66
|
-
|
67
|
-
<html lang="ja">
|
68
|
-
|
69
|
-
<head>
|
70
|
-
|
71
|
-
<meta charset="utf-8">
|
72
|
-
|
73
|
-
<script type="text/javascript">
|
74
|
-
|
75
|
-
function setFormInput() {
|
76
|
-
|
77
|
-
// 親ウィンドウの存在チェック
|
78
|
-
|
79
|
-
if (!window.opener || window.opener.closed)
|
80
|
-
|
81
|
-
{
|
82
|
-
|
83
|
-
// 親ウィンドウが存在しない場合
|
84
|
-
|
85
|
-
window.alert('メインウィンドウが見当たりません。');
|
86
|
-
|
87
|
-
}
|
88
|
-
|
89
|
-
else
|
90
|
-
|
91
|
-
{
|
92
|
-
|
93
|
-
localStorage.setItem( "inputText" , document.getElementById("inputText").value);
|
94
|
-
|
95
|
-
//window.opener.document.parentfrm.parent_input.value = document.getElementById("inputText").value;
|
96
|
-
|
97
|
-
window.close();
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
</script>
|
104
|
-
|
105
|
-
</head>
|
106
|
-
|
107
|
-
<body>
|
108
|
-
|
109
|
-
<form name="childfrm" action="" method="post">
|
110
|
-
|
111
|
-
<input type="text" name="sub_input" id="inputText" value="" class="form-control">
|
112
|
-
|
113
|
-
<input type="button" onclick="setFormInput()" value="値を渡す">
|
114
|
-
|
115
|
-
</form>
|
116
|
-
|
117
|
-
</body>
|
118
|
-
|
119
|
-
</html>
|
120
|
-
|
121
|
-
```
|