J'ai deux iframes. Ces iframes communiquent ensemble via postMessage
.Deux Iframes communiquent: SecurityError
D'un iframe, si je fais ce qui suit, cela ne fonctionne pas.
// Broadcast to all iframes.
parent.frames.forEach(function (frame) {
frame.postMessage(data, 'http://localhost:4000');
});
Erreur:
Uncaught SecurityError: Blocked a frame with origin "http://..." from accessing a frame with origin "http://...". Protocols, domains, and ports must match.
Cependant, si je fais ce qui suit, il fonctionne très bien. Aucun message d'erreur Pourquoi?
for (var i = 0 ; i < parent.frames.length ; ++i) {
parent.frames[i].postMessage(data, 'http://localhost:4000');
}
Le question ici ressemble à ce que l'on peut lire comme "Pourquoi' parent.frames.forEach' donne un _SecurityError_ quand je peux itérer sur eux dans un 'for'?" –