Monday, December 5th, 2005

Cross-document messaging: An answer to the cross domain debate?

Category: Editorial

Arve Bersvendsen, of Opera, has written about Cross document messaging, including examples to test it out in the Opera browser.

What is Cross-document messaging

Cross-document messaging is a little talked off HTML5/Web Applications 1.0 feature that the WhatWG has been specifying

How does it work?

You have senders and receivers:

Sender

function sendMessage(val){
  var receiver = document.getElementsByTagName("iframe")[0].contentDocument;
  receiver.postMessage(val);
}

Receiver

document.addEventListener('message',function(ev){
  var output = document.getElementsByTagName("textarea")[0];
  output.value += "Message from domain "
    +ev.domain+" and URI "+ev.uri+":\n";
  output.value += ev.data+"\n\n";
  parent = ev.source;
  var d = new Date();
  ev.source.postMessage("The document at "
    +location.href+" received your message at "+d);
  setTimeout(delayedResponse,2500,ev.source);
}, false);

Posted by Dion Almaer at 9:18 am
1 Comment

++---
2.7 rating from 6 votes

1 Comment »

Comments feed

xdghdyjcyjdgynv g h fghfghfg dyh tduygh

Comment by ertet — October 31, 2007

Leave a comment

You must be logged in to post a comment.