简体   繁体   English

在Firefox中的Xul中更改选项卡时获取当前URL

[英]Get current url when changing tabs in xul in firefox

I am trying to get the current URL after changing tabs in Firefox. 我正在尝试在Firefox中更改选项卡后获取当前URL。 Is it possible? 可能吗?

A complete example that logs the current URL to the Error Console each time a new tab is selected: 一个完整的示例,每次选择一个新选项卡时,会将当前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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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