在 Google Chrome 中使用 javascript 删除网站图标

发布于 2024-09-02 08:02:28 字数 329 浏览 8 评论 0原文

如何在 google chrome 中使用 Javascript 删除 favicon?目标是将其返回到浏览器默认值,在本例中为空白图像。

我发现了这个问题,但如果您离开链接,它就不起作用。 href 属性为空。

即使由于服务器上有 favicon.ico 文件而设置了 favicon,我也想将其删除并将其设置回默认值。

这只需要在 Chrome 中工作。

谢谢!

How can you remove the favicon using Javascript in google chrome? The goal is to return it to the browser default, which is in this case a blank image.

I found this question, but it doesn't work if you leave the link.href attribute as empty.

Even if the favicon is set because there is a favicon.ico file on the server, I'd like to remove it and set it back to the default.

This only needs to work in chrome.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

装纯掩盖桑 2024-09-09 08:02:28

您是否尝试过使用空的透明图像?

尝试:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oFFAADATTAuQQAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAEklEQVQ4y2NgGAWjYBSMAggAAAQQAAGFP6pyAAAAAElFTkSuQmCC

Have you tried using an empty transparent image?

Try:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oFFAADATTAuQQAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAEklEQVQ4y2NgGAWjYBSMAggAAAQQAAGFP6pyAAAAAElFTkSuQmCC
梦断已成空 2024-09-09 08:02:28

将这些评论放入答案形式:

建议:

我对 AJAX 解决方案对您有用感到有点惊讶,因为我使用的是 Chrome 4.1.249.1064 (45376),但它对我不起作用。

编辑:您似乎不需要太多 AJAX 解决方案。看来 favicon.js 就是您真正需要的。它似乎所做的就是您提到的 JavaScript 解决方案加上更多的处理(即删除现有的图标)。他们的“动态”部分只是一个document.onkeypress

编辑:附加参考:

Putting those comments into answer form:

Suggestions:

I'm a bit surprised the AJAX solution worked for you because, I'm on Chrome 4.1.249.1064 (45376) and it doesn't work for me.

EDIT: It doesn't seem like you'll need much from the AJAX solution. It seems that favicon.js is all you really need. All it seems to do is what the JavaScript solution you mentioned plus a little more handling (ie remove existing favicon). Their "dynamic" part is just a document.onkeypress.

EDIT: Additional reference:

腹黑女流氓 2024-09-09 08:02:28

作为 @MatthewFlachen 的答案和我在这里找到的内容的组合:动态生成的 favicon,可以动态生成一个使用画布 API 的空白数据 url。

link.href = document.createElement("canvas").toDataURL("image/x-icon");

As a combination of @MatthewFlachen's answer and what I found here: Dynamically generated favicon, one can dynamically generate a blank data url using the canvas API.

link.href = document.createElement("canvas").toDataURL("image/x-icon");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文