opera.extension.broadcastMessage()

By Opera Software

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 broadcasted.

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.