Developers › Dev.Opera

Button.popup

December 6, 2011 · by Opera Software

Description

This property represents the Popup for the Button. Calling Button.popup will return the popup object. You can also get and set the popup properties directly through the Button object (e.g. to set the popup width you can do 'button.popup.width = 300')

Example:

The below example shows a popup when the button is clicked. The content of the popup changes between one of three websites each time the popup is diplayed.

//
// The background process (e.g. index.html)
//

// Set the button's properties
var properties = {
  disabled: false,
  title: "My Extension",
  icon: "icon.18x18.png",
  popup: {
    href: 'popup.html', 
    width: 300 
  }
};	

// Create the button and add it to the browser UI
var button = opera.contexts.toolbar.createItem(properties);
opera.contexts.toolbar.addItem(button);

// Get the popup object to set the height property
var popup = button.popup;
popup.height = 400; 

// Open a site randomly in the popup when the button is clicked
var randomSites = ['http://touch.facebook.com', 'http://mobile.twitter.com', 'http://m.opera.com/'];
var i = 1; 
button.addEventListener('click', handleClick, false);

function handleClick(){
  // Circle through the sites on each click
  button.popup.href = randomSites[i % 3];
  i++;
}

About this article

Published inDev.Opera
DateDecember 6, 2011
AuthorOpera Software
TagsButton and Badge, extensions API, Toolbar
OriginalInternet Archive