How could a Firefox-Addon find the the tab with the"mywindow"?

Friday, July 4, 2014

I'm running Firefox 30. I have some tabs open. In one is my local-html file, in which i try to set a or to "myhtmlpage".

function init() { = 'myhtmlpage'; = 'myhtmlpage';
// or ='myhtmlpage';
// = 'myhtmlpage';

<body onload="init();">

With the following code (from some mozilla help page) I can find the contentDocument, but it simply hasn't the .id or .name property or attribute.

function openAndReuseOneTabPerURL(url) {
var wm = Components.classes["@"]
var browserEnumerator = wm.getEnumerator("navigator:browser");

// Check each browser instance for our URL
var found = false;
while (!found && browserEnumerator.hasMoreElements()) {
var browserWin = browserEnumerator.getNext();
var tabbrowser = browserWin.gBrowser;

// Check each tab of this browser instance
var numTabs = tabbrowser.browsers.length;
for (var index = 0; index < numTabs; index++) {
var currentBrowser = tabbrowser.getBrowserAtIndex(index);
if (url == currentBrowser.currentURI.spec) {

// The URL is already opened. Select this tab.
tabbrowser.selectedTab = tabbrowser.tabContainer.childNodes[index];

// Focus *this* browser-window

found = true;
return tabbrowser;
var tab;
tab = openAndReuseOneTabPerURL("file:///F:/myfile.html");
var cd = tab.contentDocument;
alert(; // doesn't exist. I checked the contentDocument with a for (var each in cd) loop.

With this contentDocument (cd) I can manipulate the content. (Like changing the value of an textarea.) So this would be fine.

But I want to find the right document-object by comparing the id, not by comparing the URL! How could I do that?

(There is a similiar question on here, and the answer suggest using linkedBrowser on the tab. But the tab hasn't that attribute. It throws an error and checking with for (var each in tab) doesn't show it either.)