在 Google Chrome 中使用 javascript 删除网站图标
如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过使用空的透明图像?
尝试:
Have you tried using an empty transparent image?
Try:
将这些评论放入答案形式:
建议:
chrome-resource://favicon/
或chrome://favicon/
我对 AJAX 解决方案对您有用感到有点惊讶,因为我使用的是 Chrome 4.1.249.1064 (45376),但它对我不起作用。
编辑:您似乎不需要太多 AJAX 解决方案。看来
favicon.js
就是您真正需要的。它似乎所做的就是您提到的 JavaScript 解决方案加上更多的处理(即删除现有的图标)。他们的“动态”部分只是一个document.onkeypress
。编辑:附加参考:
Putting those comments into answer form:
Suggestions:
chrome-resource://favicon/
orchrome://favicon/
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 adocument.onkeypress
.EDIT: Additional reference:
作为 @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");