Roy
Roy

Reputation: 243

Get current url when changing tabs in xul in firefox

I am trying to get the current URL after changing tabs in Firefox. Is it possible?

Upvotes: 1

Views: 1377

Answers (1)

Wayne
Wayne

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

Related Questions