Premium.communicator
The communicator allows communication between the iFrames that make up multi-panel creatives.
Premium.communicator.init(numPanels)
Parameter | Definition |
---|---|
numPanels | number 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)
Parameter | Definition |
---|---|
message | message 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)
Parameter | Definition |
---|---|
callback | function 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