opera.extension.broadcastMessage()

By Opera Software

From Opera 15 onward, Opera 11 & 12’s extension format is no longer supported, and instead, we’ve switched to Chromium’s extension model. Check out our new documentation for developing extensions for Opera 15 and higher and start building your own extensions.

Description:

This method is used to broadcast data from the background process to all connected environments associated with the extension, such as the preferences page, popup window and injected scripts.

Parameters:

  • data: Data to be broadcast.

Syntax:

void broadcastMessage (<DOMString> data)

Example:

//
// The background process ('/background.js').
//

// Broadcast a message to all extension environments (i.e. injected scripts, the popup window etc).
if (url === 'http://www.opera.com/') {
  opera.extension.broadcastMessage('rejoice');
}

//
// An extension environment (e.g. '/popup.js')
//

// Receive the message using the onmessage handler
opera.extension.onmessage = function(event) {
  var message = event.data;
  if (message === 'rejoice') {
    initConfettiSequence();
  }
};

This article is licensed under a Creative Commons Attribution 3.0 Unported license.

Comments

No new comments accepted.