« Documentation Home

opera.extension.broadcastMessage()

This documentation relates to Opera's now deprecated .oex Extension API framework for Opera versions <= 12.15 and also provided by our OEX2NEX shim library.

For the latest Opera Extensions API documentation for Opera versions > 12.15 please consult the latest Opera Extensions API documentation online.

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:

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();
  }
};