function init() { var containor; var links; var goodUrls; var pages; var page; var pagesTab; var newTab; var initialized; var win; openAndReuseOneTabPerAttribute("getlinksmain", "www.ebaumsworld.com") alert(window.getBrowser().selectedBrowser.contentDocument.location); if (window.getBrowser().selectedBrowser.contentDocument.location.toString().match("ebaumsworld") === null) { alert("not ebaums!"); return; } containor = window.getBrowser().selectedBrowser.contentDocument; links = containor.getElementsByTagName("a"); alert(links[1].tagName); page = 1; goodUrls = Array(); pages = Array(); for (var i in links) { var url = i.href; if (url.match("page=")) { for (var k in pages) { if (k == url) { continue; } pages[url] = i; } } if (url.match("pictures\/view") || url.match("video\/watch") || url.match("jokes\/read")) { for (var j in goodUrls) { if (j == url) { continue; } goodUrls[url] = i; } } } alert(goodUrls[0]); openAndReuseOneTabPerAttribute("getlinksmain", goodUrls[0]); } function openAndReuseOneTabPerAttribute(attrName, url) { var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator); for (var found = false, index = 0, browserInstance = wm.getEnumerator('navigator:browser').getNext().getBrowser(); index < browserInstance.mTabContainer.childNodes.length && !found; index++) { // Get the next tab var currentTab = browserInstance.mTabContainer.childNodes[index]; // Does this tab contain our custom attribute? if (currentTab.hasAttribute(attrName)) { // Yes--select and focus it. browserInstance.selectedTab = currentTab; // Focus *this* browser in case another one is currently focused browserInstance.focus(); found = true; } } if (!found) { // Our tab isn't open. Open it now. var browserEnumerator = wm.getEnumerator("navigator:browser"); var browserInstance = browserEnumerator.getNext().getBrowser(); // Create tab var newTab = browserInstance.addTab(url); newTab.setAttribute(attrName, "xyz"); // Focus tab browserInstance.selectedTab = newTab; // Focus *this* browser in case another one is currently focused browserInstance.focus(); } }