Developers › Dev.Opera

opera.extension.broadcastMessage()

December 6, 2011 · by Opera Software

Description:

This method is used to broadcast data 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();
  }
};

About this article

Published inDev.Opera
DateDecember 6, 2011
AuthorOpera Software
Tagsextensions API, messaging
OriginalInternet Archive