在firefox中更改xul中的选项卡时获取当前URL

时间:2011-12-02 11:04:48

标签: javascript tabs firefox-addon xul

我想在Firefox中更改标签后获取当前的URL。有可能吗?

1 个答案:

答案 0 :(得分:5)

每次选择新标签时,将当前URL记录到错误控制台的完整示例:

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