Firefox extension get tab index - javascript

var browser = gBrowser.getBrowserForTab(event.target);
How I can take index of this tab?

Try Array.slice(getBrowser().tabs).indexOf(aTab)

Related

Chrome Debugging Chrome Extension Javascript

I am trying to debug a chrome extension. I have opened up the background page in the extension page but I was wondering if there was a way to look at the array type that I have.
For example, I have the code
function main() {
var cells = document.getElementsByClassName('sectionFieldInstructor');
var length = cells.length;
var professors = [];
var profCount = 0;
Where my cells is the teachers in the list. I would like to view which teachers I have in the cells array.
Also, in the inspected page, the teachers name is listed as
A. TEACHER<br/>
Would it be affected by that?
Thanks!
You can do that with Chrome developer tools. The easiset way is to add
var cells = document.getElementsByClassName('sectionFieldInstructor');
console.log(cells); //Add this line
var length = cells.length;
Then it will be displayed in your console. (There is a tab in dev tools called console.)
You can call that function from the console as well by typing:
main();
Hope this helps

How can i get all URL's of a google chrome window

im currently developing an extension, but im kind of lost by the moment.
Basically, what i want it to do, its kind of what "OneTab" extension does.
So my first question is, after adding the listener to the extension button, and executing the function, i want to get all the url's of the current window, and store them in an array and the show them in the html file.
So im using this:
chrome.tabs.getSelected(null,function(tab) {
var tablink = tab.url;
console.log(tablink);
});
but its not working and im not sure how it will check all the tabs one by one.
Thanks in advance.
chrome.tabs.getSelected() will only get you the current tab.
In order to get the list of all the tabs in the current window, you need to use the chrome.windows API. This API will return an object of the current window which will have the list of tab objects.
Here is the sample code:
chrome.windows.getCurrent({"populate":true}, function(currentWindow) {
var tabURLs = [];
var tabs = currentWindow.tabs;
for (var i=0; i<tabs.length; i++) {
tabURLs.push(tabs[i].url);
}
console.log(tabURLs);
});
For details check:
http://developer.chrome.com/extensions/windows.html#method-getCurrent

Local storage in javascript that supports both browsers (Chrome and Firefox)

I was not able to retrieve my local storage values in Firefox 4 web browser when i reloaded the same page.
Note: The code below is working fine in the latest Google Chrome web browser
My code:
//Set item
var bookmark_value = document.getElementById('bookmark').value;
var storageIndex = "Bookmarked_Page_" + i;
localStorage[storageIndex] = bookmark_value;
//get item
document.bookmark["bookmark"].value = localStorage["Bookmarked_Page_" + i];
You shouldn't rely on the browser adding elements with an ID directly onto the document.
//get item
document.getElementById('bookmark').value = localStorage["Bookmarked_Page_" + i];
typo?
document.bookmark["bookmark"].value
should be
document.getElementById('bookmark').value
Edit
Oh I think that's your problem, check out this question and answer: Is "localStorage" in Firefox only working when the page is online?

open page in new instance of browser

please tell me how to open a page on click of hyper link in new browser instance (so that it should not be blocked by popup blocker) in flash AS3/ javascript
Thanks
You can open on a new tab (not on a new browser!) by doing this:
var urlRequest:URLRequest = new URLRequest("http://stackoverflow.com");
navigateToURL(urlRequest, "_blank");
Please, use it wisely...
JavaScript
// spawnWindow( 'www.duh.com', 'windowRef' )
function spawnWindow(URL, Name) {
var features = 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=900,height=700';
window.open(URL, Name, features);
}
AS3 code to call JS function
var retVal:int = ExternalInterface.call("spawnWindow",address,newId);
It is impossible! Unless you use ActiveX.

Firefox get unique id of tabs for extension development

I'm developing a Firefox extension, and I need get and work with unique id of tabs.
How I can do it?
Thanks!
If you use the Firefox SDK, you can get the id of the active tab by using:
var tabs = require('sdk/tabs');
var activeTabId = tabs.activeTab.id;
I have a solution.
You can try this out.
The function below will return you a unique id of the current tab.
var get_current_tab_id = function()
{
var doc = gBrowser.contentDocument; //Gets the current document.
var tab = null;
var targetBrowserIndex = gBrowser.getBrowserIndexForDocument(doc);
if (targetBrowserIndex != -1)
tab = gBrowser.tabContainer.childNodes[targetBrowserIndex];
else
return(null);
return(tab.linkedPanel);
}
Check out the documentation for nsIWindowMediator, which provides information and access to all open windows within Firefox.
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIWindowMediator#getEnumerator
If you mean that you want to interact in any way with the open firefox tabs via javascript then the answer is that you cannot.

Categories

Resources