2009-06-13 2 views
0

Ich spiele mit jetpack herum, um den Titel (und im Idealfall das Favicon) bestimmter Seiten zu ändern.Warum werden der Titel und das Favicon des Fensters/Tabs nicht aktualisiert?

Firebug zeigt, dass der HTML der Seite korrekt geändert wurde, aber Firefox wird nur nicht den Titel des Fensters und/oder Registerkarte aktualisieren.

Das muss irgendwie möglich sein, da Twitter Search genau das macht. Es aktualisiert den Titel, da mehr Suchergebnisse angezeigt werden, nicht wahr?

Ich denke, ich vermisse nur etwas ... keine Ahnung?

Beispielcode, wie im Kommentar vorgeschlagen:

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

Irritierend, dauert es nicht einmal Logs zeigen mehr seit Jetpack und Firebug haben in der Zwischenzeit aktualisiert: p
ich diesen Code erwarten würde zu Ersetzen Sie den Titel von stackoverflow.com Seiten durch "Foo" - aber dies ist nur ein Beispiel, ersetzen Sie stackoverflow.com durch alles andere, wenn das helfen könnte, dh wahrscheinlich eine Website mit weniger JavaScript Magie als SO.com.

Update:
löste ich das Problem mit Hilfe der Antwort unten.
Das Arbeits Beispiel sieht wie folgt aus:

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

Vielleicht ein Beispielcode. –

Antwort

1

könnte

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

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

Werke für mich

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

+1

stackoverflow.comanywebsitenamenamestartingwithcom.com würde funktionieren - kleine Details –

Verwandte Themen