我想创建一个Firefox扩展程序,该扩展名在地址栏中创建新图标,或用扩展名中指定的firefox扩展名代替现有图标。

然后,仅在用户查看特定域时,添加一些JavaScript才能显示此自定义徽标。

如果这对于位置/地址栏不可行,则可以在状态栏上显示徽标(再次由仅当用户在特定域上显示徽标的JavaScript驱动)。

可以做到吗?

我不认为favicon一个人会解决我的问题。我希望仅在用户在特定域上显示图标/徽标(例如xyz.com/testpage.html或abc.com/anothertest.html)

有帮助吗?

解决方案

你可以这样做 Greasemonkey. 。在这里,您有一个可以使用的快速脚本。

//create the icon
a=document.createElement("link");
a.setAttribute("rel", "icon");
a.setAttribute("href","http://www.google.com/favicon.ico");

//append the icon to the head
document.documentElement.firstChild.appendChild(a);

GreaseMonKey的手册:(添加脚本)

如果您要更改的网站 已经有一个, ,您将必须做类似的事情

// get the head elements
head = document.documentElement.firstElementChild.childNodes;

//delete the existing favicon
for(i in head){
    if((head[i].rel == "shortcut icon")||(head[i].rel == "icon")){
         head.removeChild(head[i]);
    }
}

在设置新的Favicon之前,但是我无法正常工作。

有一个 为Favicon操纵创建标准对象的项目 那应该可以工作,但对我不起作用。

其他提示

您可以更改创建这样的链接元素的DOM:

<link rel="icon" type="image/png" href="/somepath/image.png" />
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top