检测选项卡关闭(关闭后)从Firefox扩展 [英] Detecting tab closed (after closed) from firefox extension

查看:152
本文介绍了检测选项卡关闭(关闭后)从Firefox扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的Firefox扩展从浏览器中的所有选项卡创建一个URL列表。为了保持列表更新,我需要知道何时关闭标签。



我试过使用

  window.addEventListener(TabClos​​e,tabRemoved,false); 

然而,这个被调用之前tab实际上是关闭的,这导致我的更新tablist仍然包含关闭标签网址。



我通过迭代所有浏览器更新标签列表,如下所示:

  function()
{
gBrowser = window.getBrowser();
tabs = gBrowser.browsers;
urls = [];

for(var i = 0; i< tabs.length; i ++)
{
if(typeof(tabs [i])!=undefined){
urls.push(tabs [i] .webNavigation.currentURI.spec);
}
}

返回网址;





$ b

所以我要找的是一个事件,已关闭,或者获取已关闭的选项卡的索引,以便在迭代浏览器时跳过它。



任何人都知道任何此类事件或其他解决方案给我的问题?

提前致谢!

解决方案

是我做了什么来解决这个问题:

$ pre $ tab $移动=函数$ ev
$ $ $ logTabs( [ev.target._tPos]); / * ev.target._tPos =关闭标签的索引* /
}

logTabs =函数(excludedelist)
{
...
urls = getTabURLs(); $(i = 0; i {
if(typeof(excludelist)!=undefined&&& excludelist.indexOf != -1)
continue;

doStuff(urls [i]);
...


I'm trying to get my firefox extension to create a url list from all tabs in the browser. To keep the list updated I need to know when a tab has been closed.

I've tried using

window.addEventListener("TabClose", tabRemoved, false);

However, this gets called BEFORE the tab is actually closed, which results in my updated tablist still containing the closed tabs url.

I update the tab list by iterating all browsers, like so:

function ()
{
    gBrowser = window.getBrowser();
    tabs = gBrowser.browsers;
    urls = [];

    for (var i = 0; i < tabs.length; i++)
    {
        if (typeof(tabs[i]) != "undefined") {
            urls.push(tabs[i].webNavigation.currentURI.spec);
        }
    }

    return urls;
}

So what I'm looking for is an event that gets called AFTER a tab has been closed, or a way to get the index of the tab that was closed so that I can skip it while iterating browsers.

Anyone know of any such event or other solutions to my problem?

Thanks in advance!

解决方案

Here is what I did to solve the problem:

tabRemoved = function (ev)
{
    logTabs([ev.target._tPos]); /* ev.target._tPos = index of tab that was closed */
}

logTabs = function (excludelist)
{
    ...
    urls = getTabURLs();
    for(var i = 0; i < urls.length; i++)
    {
        if(typeof(excludelist) != "undefined" && excludelist.indexOf(i) != -1)
            continue;

        doStuff(urls[i]);
    ...

这篇关于检测选项卡关闭(关闭后)从Firefox扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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