Skip to main content

Premium.communicator

The communicator allows communication between the iFrames that make up multi-panel creatives.

Premium.communicator.init(numPanels)

ParameterDefinition
numPanelsnumber of persistent panels that need to communicate together required

Initiates the communicator. Each panel will receive messages once all panels are loaded.

Premium.communicator.init(3);

Premium.communicator.api.sendMessage(message)

ParameterDefinition
messagemessage to be sent (usually an object) required

Sends a message.

var message = { from: 'id1', action: 'do-something' };
Premium.communicator.api.sendMessage(message);

Premium.communicator.api.receiveMessage(func)

ParameterDefinition
callbackfunction will be called when a message is sent. Called with one parameter - the message required

Set a callback to receive messages.

Premium.communicator.api.receiveMessage(function (message) {
if (message.action === 'do-something') {
// do something here
}
});

Premium.communicator.sharedObj

A shared object for sharing data between panels. It is available immediately inside Premium.creative.init; there is no need to initialize the communicator.

// in one panel
Premium.communicator.sharedObj.frameIndex = 0;

// in another panel
Premium.communicator.sharedObj.frameIndex === 0; // true