Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么窗口/选项卡的标题和图标没有更新?_Javascript_Jquery_Firefox Addon_Firefox Addon Sdk - Fatal编程技术网

Javascript 为什么窗口/选项卡的标题和图标没有更新?

Javascript 为什么窗口/选项卡的标题和图标没有更新?,javascript,jquery,firefox-addon,firefox-addon-sdk,Javascript,Jquery,Firefox Addon,Firefox Addon Sdk,我正在玩弄改变某些页面的标题(最好是favicon) 显示页面的HTML已正确更改,但Firefox不会更新窗口和/或选项卡的标题 无论如何,这是可能的,因为Twitter搜索正是这么做的。随着更多搜索结果的出现,它正在更新标题,不是吗 我想我只是错过了一些东西。。。有什么想法吗 注释中建议的示例代码: function replaceTitle(doc) { if (doc.location.protocol == "http:" || doc.location.protocol =

我正在玩弄改变某些页面的标题(最好是favicon)

显示页面的HTML已正确更改,但Firefox不会更新窗口和/或选项卡的标题

无论如何,这是可能的,因为Twitter搜索正是这么做的。随着更多搜索结果的出现,它正在更新标题,不是吗

我想我只是错过了一些东西。。。有什么想法吗

注释中建议的示例代码:

function replaceTitle(doc) 
{
    if (doc.location.protocol == "http:" || doc.location.protocol == "https:")
    {

        var host=doc.location.host;
        if(host.indexOf("stackoverflow.com")>=0)
        {
            var title=doc.getElementsByTagName("title")
            console.log(title);

            if(title)
            {
                var val=title[0];
                if(val)
                {
                    console.log("val", val);
                    console.log("valx", val.textContent);
                    val.textContent="Foo";
                    console.log("valz", val.textContent);
                }
            }
        }
    }      
}


var state = "on";

function toggleState()
{
    if( state == "off" )
    {
        jetpack.tabs.onReady(replaceTitle);
        state = "on";
    }
    else
    {
        jetpack.tabs.onReady.unbind(replaceTitle);
        state = "off";
    }
    console.log(state);
    // This is a temporary way of keeping all browser window states
    // in sync. We are working on a better API for this.  
    /*  
    widgets.forEach(function(widget) {
    widget.defaultView.wrappedJSObject.setState(state);
    });
    */
}

jetpack.statusBar.append(
    {
        html: "Boo",
        onReady: function(widget) 
                {
                    console.log("ready");
                    // This is a temporary way of keeping all browser window states
                    // in sync. We are working on a better API for this.
                    /*
                    widgets.push(widget);
                    widget.defaultView.wrappedJSObject.setState(state);
                    */
                    $(widget).click(toggleState);
                },
        onUnload: function(widget) 
                {
                    console.log("unload");
                    /*
                    widgets.splice(widgets.indexOf(widget), 1);
                    */
                },
        width: 42
    });

console.log("Test");
令人恼火的是,它甚至不再显示日志,因为jetpack和firebug已经同时更新:p
我希望这段代码将stackoverflow.com页面的标题替换为“Foo”-但这只是一个示例,如果可能有帮助的话,将stackoverflow.com替换为其他任何内容,例如,可能是一个javascript魔力不如SO.com的站点

更新:
我通过下面的答案解决了这个问题。
工作示例如下所示:

function replaceTitle() 
{
  var doc=this.contentDocument;
  console.log("replaceTitle "+ doc);
  if(doc)
  {
    var location = doc.location;

    if ( (location.protocol == "http:" || location.protocol == "https:")
      && location.host.indexOf("stackoverflow.com") !== -1 )
    {
      doc.title = "Foo";
      console.log("Title set to "+doc.title);
    }      
    else
    {
      console.log("Location "+location);
    }
  }
}


var state = "on";

function toggleState()
{
  if( state == "off" )
  {
    state = "on";
    jetpack.tabs.onReady(replaceTitle);
  }
  else
  {
    state = "off";
    jetpack.tabs.onReady.unbind(replaceTitle);
  }
  console.log(state);
}

jetpack.statusBar.append(
{
  html: "Boo",
  onReady: function(widget) 
    {
      console.log("ready: "+state);
      $(widget).click(toggleState);
    },
  onUnload: function(widget) 
    {
      console.log("unload");
    },
  width: 42
});

console.log("Testing");
我想试试

function replaceTitle(doc) 
{
  var location = doc.location;

  if ( (location.protocol == "http:" || location.protocol == "https:")
       && location.host.indexOf("stackoverflow.com") !== -1 ) {
    document.title = "Foo";
  }      
}
为我工作


如果您回到firebug 1.4.0b4,它将修复您遇到的控制台问题


stackoverflow.com任何网站名称StartingWithcom.com都可以-次要细节