Get current url when changing tabs in xul in firefox

﹥>﹥吖頭↗ 提交于 2019-12-08 08:03:48

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/8355354/get-current-url-when-changing-tabs-in-xul-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!