在firefox中更改xul中的选项卡时获取当前URL [英] Get current url when changing tabs in xul in firefox

查看:97
本文介绍了在firefox中更改xul中的选项卡时获取当前URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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

这篇关于在firefox中更改xul中的选项卡时获取当前URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆