BrowserTab.title
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);About this article
| Published in | Dev.Opera |
|---|---|
| Date | April 26, 2012 |
| Author | Opera Software |
| Tags | extensions API, Windows and Tabs |
| Original | Internet Archive |