opera.extension.windows.getLastFocused()

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 getLastFocused() method provides a way to obtain the currently selected browser window, if any. The result depends on whether a browser window is open or not. If there are no open browser windows, null is returned, otherwise a BrowserWindow object is returned.

Parameters:

None

Syntax:

BrowserWindow getLastFocused ()

Example:

The following example creates a button on the toolbar. When the button is clicked, the ID (unique identifier) of the browser window currently in focus is shown in the button's badge.

//
// 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",
  badge: {
    backgroundColor: '#cc0000',
    color: '#ffffff'
  }
};

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

button.addEventListener('click', handleClick, false);

function handleClick() {
  var win = opera.extension.windows.getLastFocused();
  button.badge.textContent = win.id;
}

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

Comments

No new comments accepted.