Remove favicon using javascript in Google 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.
Thank开发者_JS百科s!
Have you tried using an empty transparent image?
Try:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oFFAADATTAuQQAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAEklEQVQ4y2NgGAWjYBSMAggAAAQQAAGFP6pyAAAAAElFTkSuQmCC
Putting those comments into answer form:
Suggestions:
chrome-resource://favicon/
orchrome://favicon/
- Dynamic Favicon with AJAX
- Chrome extension (hopefully you can base it off of this)
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:
- chrome.tabs.executeScript
- Whitelisting the favicon
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");
精彩评论