0

我想创建一个 Firefox 扩展,在地址栏中创建一个新图标或用扩展中指定的图标替换现有图标。

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

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

这可以做到吗?

我认为单独的 favicon 不能解决我的问题。我希望仅当用户位于特定域(例如 xyz.com/testPage.html 或 abc.com/anotherTest.html)时才能显示图标/徽标

4

2 回答 2

1

你可以使用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]);
    }
}

在设置新的图标之前,但我无法让它工作。

有一个项目可以为网站图标操作创建一个标准对象,该对象应该可以工作,但对我不起作用。

于 2009-08-25T17:32:51.320 回答
0

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

<link rel="icon" type="image/png" href="/somepath/image.png" />
于 2009-08-25T17:20:10.377 回答