Skip to content

Commit b017745

Browse files
committed
Timeout for frame availability
1 parent 08776b8 commit b017745

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,19 @@
165165
.empty()
166166
.append($iframe);
167167

168+
var tries = 0;
168169
var sendSources = setInterval(function() {
169-
$iframe.get(0).contentWindow.postMessage(data, "*");
170+
// Stop after 10 seconds
171+
if (tries >= 100) {
172+
return clearInterval(sendSources);
173+
}
174+
tries++;
175+
var iframe = $iframe.get(0).contentWindow;
176+
if (iframe) {
177+
iframe.postMessage(data, "*");
178+
} else {
179+
console.warn("Frame is not available");
180+
}
170181
}, 100);
171182

172183
window.addEventListener("message", function() {

0 commit comments

Comments
 (0)