BrowserTab.url
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:
Attribute
The readonly url
attribute exposes the document URL of the browser tab. On getting, the implementation returns the URL of the current document if the tab is open, otherwise it returns an empty string.
Property
When specified as an item in a BrowserTabProperties
object, the url
property specifies the location for a browser tab as a URL.
When creating a browser tab, if this property is not specified the browser will use its default URL.
When updating a browser tab, if this property is not specified the default behaviour is to leave the URL unchanged.
Syntax:
Attribute
readonly string url
Property
DOMString url
Example:
The following example creates a button in the browser toolbar. When the button is clicked, the last focused window is detected. A new tab is then created with different URL depending on whether the window is private or not.
//
// The background process (e.g. index.html)
//
// Specify the properties of the button before creating it.
var UIItemProperties = {
disabled: false,
title: "Window creation test",
icon: "images/icon_18.png",
onclick: function() {
// Get the last focused window
var thisWin = opera.extension.windows.getLastFocused();
// Create an empty tab properties object
var tabProps = {};
// Add a tab URL depending on whether the window is private or not
if (thisWin.private) {
tabProps.url = 'http://www.facebook.com/';
} else {
tabProps.url = 'http://www.wikipedia.org/';
}
// Open a new tab with the relevant URL
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