How could a Firefox-Addon find the the tab with the window.name="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 window.id or document.id to "myhtmlpage".



...
function init() {
document.name = 'myhtmlpage';
document.id = 'myhtmlpage';
// or window.name ='myhtmlpage';
// window.id = 'myhtmlpage';
}

</script></head>
<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["@http://ift.tt/1ijOkEp"]
.getService(Components.interfaces.nsIWindowMediator);
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
browserWin.focus();

found = true;
return tabbrowser;
break;
}
}
}
}
var tab;
tab = openAndReuseOneTabPerURL("file:///F:/myfile.html");
var cd = tab.contentDocument;
alert(cd.id); // 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.)







http://ift.tt/1rt26Yr