简体   繁体   中英

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM