Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 084d9491c3
Fetching contributors…

Cannot retrieve contributors at this time

39 lines (28 sloc) 1.41 kb


PostMessager is a MooTools plugin that acts as a wrapper for the window.postMessage API which is available in IE8+, Firefox 3.1+, Opera 9+, Safari, and Chrome. PostMessager also normalizes the onMessage event for use within MooTools.


How to Use

PostMessager instances can be created at any time. Two arguments are accepted: the destination window and the instance options.


/* Get hold of an iFrame */
var domain = '';
var iframe ='listenerFrame').contentWindow;

/* Create a PostMessager instance */
var messager = new PostMessager(iframe,{
    allowReceive: true,
    allowSend: true,
    validReceiveURIs: [''],
    onSend: function(message,dest) {
        console.log('sending "',message,'" to ',dest);
    onReceive: function(message,source,origin) {
        console.log('received message "',message,'" from ',origin,' at ',source);
        this.reply('Got it!',source,origin);

/* Send a message to the iFrame! */
messager.send('Hello from the parent window!',domain);

PostMessager handles sending, receiving, and replying to messages. Optimally you would add an instance to each frame.

For specific usage and options, please read the documentation or visit

Jump to Line
Something went wrong with that request. Please try again.