« Documentation Home

BrowserTab.title

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 title attribute exposes the title of the current document within the browser tab. On getting, the browser only returns the title if the tab is open, otherwise an empty string is returned.

Syntax:

readonly string title // maps to document.title

Example:

The following example creates a button in the browser toolbar. When the button is clicked, the title of the current tab is retrieved. Then a search is performed in a new tab, using the title as the search query.

//
// 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 the current tab as a BrowserTab object
    var thisTab = opera.extension.tabs.getSelected();
    
    // Get the title of the tab's document and encode special characters
    var title = encodeURIComponent(thisTab.title);
    
    // Create a tab searching DuckDuckGo for the specified title
    var tabProps = {
      url: 'http://duckduckgo.com/?q=' + title
    }
    opera.extension.tabs.create(tabProps);
  }
};

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