BrowserTab.title

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

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

Comments

  • photo

    Matze

    Wednesday, January 9, 2013

    How can I access the screenshots of all opened tabs by a popup JavaScript?

    This is what I got in popup.js:

    var tabResults = opera.extension.bgProcess.opera.extension.tabs.getAll();
    [...]
    function showScreenshot(arrayPosition){
    // Check the Screenshot API is available
    if(opera.extension.bgProcess.opera.extension.getScreenshot){//this is rerutning false!? I also tried it with opera.extension.getScreenshot and with getScreenshot()
    function applyScreenshot(imageData) {
    // Write the screenshot image data to the canvas context
    document.getElementById('previewCanvas').getContext('2d').putImageData(imageData, 0, 0);
    }
    // Use the API's method to execute the callback function
    tabResults[arrayPosition].getScreenshot(applyScreenshot);
    }
    }
No new comments accepted.