teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コードの記述を削除しました。

2018/12/04 04:50

投稿

退会済みユーザー
answer CHANGED
@@ -1,61 +1,2 @@
1
- 一先ず今後の方の為にサンプルコードを記述しておきます。
2
- localstorageを使ったサンプルコードです。
3
- parent.html
4
- ```
5
- <!DOCTYPE html>
1
+ 回答者のお答えの中で正解ではないようなので、
6
- <html lang="ja">
7
- <head>
8
- <meta charset="utf-8">
9
- <script>
2
+ コードの記述を削除しました。
10
- // 子ウィンドウを開く
11
- function openWindow() {
12
- window.open('child.html', 'child', 'width=500,height=250')
13
- }
14
- //フォーカスがテキストボックスに当たった時
15
- function focusWindow() {
16
- var txt = localStorage.getItem("inputText");
17
- document.getElementById("inputText").value = txt;
18
- localStorage.clear();
19
- }
20
- </script>
21
- </head>
22
- <body>
23
- <form name="parentfrm" action="" method="post">
24
- <input type="text" id="inputText" class="form-control" name="parent_input" value="" placeholder="ここに値がセットされます。" onFocus="focusWindow()">
25
- </form>
26
- <a href="" onClick="openWindow()">子画面を開く</a>
27
- </body>
28
- </html>
29
-
30
- ```
31
- child.html
32
- ```
33
- <!DOCTYPE html>
34
- <html lang="ja">
35
- <head>
36
- <meta charset="utf-8">
37
- <script type="text/javascript">
38
- function setFormInput() {
39
- // 親ウィンドウの存在チェック
40
- if (!window.opener || window.opener.closed)
41
- {
42
- // 親ウィンドウが存在しない場合
43
- window.alert('メインウィンドウが見当たりません。');
44
- }
45
- else
46
- {
47
- localStorage.setItem( "inputText" , document.getElementById("inputText").value);
48
- //window.opener.document.parentfrm.parent_input.value = document.getElementById("inputText").value;
49
- window.close();
50
- }
51
- }
52
- </script>
53
- </head>
54
- <body>
55
- <form name="childfrm" action="" method="post">
56
- <input type="text" name="sub_input" id="inputText" value="" class="form-control">
57
- <input type="button" onclick="setFormInput()" value="値を渡す">
58
- </form>
59
- </body>
60
- </html>
61
- ```