2009-06-13 19 views
0

私はjetpackで遊んで、特定のページのタイトル(そして理想的にはファビコン)を変更しています。ウィンドウ/タブのタイトルとファビコンが更新されないのはなぜですか?

Firebugは、ページのHTMLが正しく変更されたことを示していますが、Firefoxはウィンドウやタブのタイトルを更新しません。

これは、Twitter Searchが正確に行っているので、何とかして、可能なはずです。より多くの検索結果が表示されるようにタイトルを更新していますか?

私はちょうど何かを見逃していると思う...任意のアイデア?

例のコードのコメントで提案されているように:P
私はこのコードを期待したい:イライラ

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

ジェットパックと放火魔がその間に更新されていることから、それももうログは表示されません。 stackoverflow.comのタイトルを "Foo"に置き換えてください。これはほんの一例です。stackoverflow.comを他のもの、たとえばSO.comよりもjavascriptのマジックの少ないサイトに置き換えてください。

更新:
私は以下の答えの助けを借りて問題を解決しました。
実施例はこのようになります:あなたが戻ってダウン放火魔にそれが意志1.4.0b4場合

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"); 
+0

。 –

答えて

1

は私にとって

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

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

作品

http://pastebin.me/4a3550e0dbe19?framepage

+1

stackoverflow.com中小企業の皆様へ –

関連する問題