Reputation: 162
I am developing a plugin for firefox. In which i have to open a hidden tab and access its content through javascript and close it afterwards.
Following is the code i am using for accessing content of a tab:
var newTabBrowser = gBrowser.getBrowserForTab(gBrowser.addTab("www.kayak.com/flights#/BOM-ORL/2013-05-14/2013-06-19"));
var contentdata = "";
newTabBrowser.addEventListener("load", function () {
contentdata = contentdata + newTabBrowser.contentDocument.body.innerHTML;
load = load + 1;
if(load == 5) {
var DOMPars = new DOMParser();
var dom = DOMPars.parseFromString(contentdata, "text/html");
var priceNode = dom.getElementById('low_price');
}
}, true);
How can i hide this tab in the browser?
Upvotes: 0
Views: 1115
Reputation: 1087
It look like you just need to create a permanent, invisible page and access its DOM.
Addon-SDK provide a page-work module. Do this what you want?
Upvotes: 0
Reputation: 1430
If you store a reference to the tab you open with addTab, you can hide that tab using css or other available methods. For example:
var newTab = gBrowser.addTab("www.kayak.com/flights#/BOM-ORL/2013-05-14/2013-06-19");
newTab.setAttribute("style", "display: none");
var newTabBrowser = gBrowser.getBrowserForTab(newTab);
newTabBrowser.loadCount = 0;
var contentdata = "";
newTabBrowser.addEventListener("load", function () {
contentdata = contentdata + newTabBrowser.contentDocument.body.innerHTML;
this.loadCount = this.loadCount + 1;
if(this.loadCount == 5) {
var DOMPars = new DOMParser();
var dom = DOMPars.parseFromString(contentdata, "text/html");
var priceNode = dom.getElementById('low_price');
}
}, true);
Upvotes: 0