質問編集履歴

2

親ページのサンプルコードが「cotentWindow」になっていたので修正しました。

2017/06/21 07:37

投稿

nao84
nao84

スコア23

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
  var message = 'hogefuga';
30
30
 
31
- cotentWindow.postMessage(message,"https://B.jp");
31
+ contentWindow.postMessage(message,"https://B.jp");
32
32
 
33
33
  ```
34
34
 
@@ -104,7 +104,7 @@
104
104
 
105
105
  var message = 'hogefuga';
106
106
 
107
- cotentWindow.postMessage(message,"https://B.jp");
107
+ contentWindow.postMessage(message,"https://B.jp");
108
108
 
109
109
  }
110
110
 

1

ご質問のご返答をどこに書いたらいいのかわからないため、メインの投稿を修正いたしました。

2017/06/21 07:37

投稿

nao84
nao84

スコア23

test CHANGED
File without changes
test CHANGED
@@ -57,3 +57,55 @@
57
57
  });
58
58
 
59
59
  ```
60
+
61
+
62
+
63
+ ★追記★
64
+
65
+
66
+
67
+ 親ページのconsoleには、
68
+
69
+
70
+
71
+ > Uncaught TypeError: Cannot read property 'postMessage' of undefined
72
+
73
+ > at <anonymous>:1:311
74
+
75
+ > at dispatch (jquery.min.js:3)
76
+
77
+ > at i (jquery.min.js:3)
78
+
79
+
80
+
81
+ と出ています。
82
+
83
+ (jQueryが読まれる前に処理が走ってしまっているからかと思い、
84
+
85
+ 念のため下記の様に修正してみましたが、やはりエラーが生じます。)
86
+
87
+
88
+
89
+ 親ページ
90
+
91
+ ```javascript
92
+
93
+ //jQuery呼び出し前に処理することを避ける。
94
+
95
+ if(typeof jQuery == "undifined"){
96
+
97
+ document.write("script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'><\/script>");
98
+
99
+ }
100
+
101
+ //念のためjQueryがあることを確認しつつ実行
102
+
103
+ if(typeof jQuery !== "undifined"){
104
+
105
+ var message = 'hogefuga';
106
+
107
+ cotentWindow.postMessage(message,"https://B.jp");
108
+
109
+ }
110
+
111
+ ```