BrowserTab.selected

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:

The readonly selected attribute exposes the selected state of the browser tab. On getting, the selected attribute returns true if the browser tab is currently selected, otherwise, it returns false.

Syntax:

readonly boolean selected

Example:

The following example creates a button on the browser toolbar. When the button is clicked, the script loops through all open tabs and closes all tabs that are not currently selected.

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

// Specify the properties of the button before creating it.
var UIItemProperties = {
  disabled: false,
  title: "Example extension",
  icon: "images/icon_18.png",
  onclick: function() {
    // Get all tabs in the current window
    var tabs = opera.extension.tabs.getAll();
    
    // Loop through all the tabs
    for (var i = 0, len = tabs.length; i < len; i++) {
        
      // Close tabs that are not currently selected
      if (tabs[i].selected === false) {
        tabs[i].close();
      }
      
    }
  }
};

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

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

Comments

No new comments accepted.