« Documentation Home

BrowserTab.selected

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:

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