Reputation: 243
I am trying to get the current URL after changing tabs in Firefox. Is it possible?
Upvotes: 1
Views: 1377
Reputation: 60414
A complete example that logs the current URL to the Error Console each time a new tab is selected:
function LOG(msg) {
var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
consoleService.logStringMessage(msg);
}
function onTabChange() {
var href = gBrowser.contentDocument.location.href;
LOG(href);
}
window.addEventListener("load", function(e) {
gBrowser.tabContainer.addEventListener("TabSelect", onTabChange, false);
}, false);
window.addEventListener("unload", function(e) {
gBrowser.tabContainer.removeEventListener("TabSelect", onTabChange, false);
}, false);
Upvotes: 5