views:

635

answers:

3

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!

+2  A: 

Have you tried using an empty transparent image?

Try:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oFFAADATTAuQQAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAEklEQVQ4y2NgGAWjYBSMAggAAAQQAAGFP6pyAAAAAElFTkSuQmCC
Matthew Flaschen
No, I'll give that a shot. I'd prefer the browser default, is there a URL which can be used to reference the current google chrome default?
Cyclone
Maybe consider detecting the browser being used and if it is chrome use: `chrome-resource://favicon/` ?
nevets1219
The code from the question I linked to does not work for Chrome. What can I do for chrome to do that?
Cyclone
What does the error console say? http://stackoverflow.com/questions/45965/how-do-i-use-the-javascript-console-in-google-chrome
nevets1219
It does not say anything, I checked the webkit inspector console.
Cyclone
Is this running as a [Chrome user script](http://www.chromium.org/developers/design-documents/user-scripts)?
Matthew Flaschen
It is injected into the page via plugin (`chrome.tabs.executeScript`)
Cyclone
I was able to use that script you linked and call it from the body's onload. It works at least as far as I can tell. Try `chrome://favicon/` and it should give you a favicon. I don't use Chrome all that often so I'm not sure if that's the icon you want. Make sure to clear the cache?
nevets1219
That is indeed the icon I want. However, I need the script to be called at runtime, onload is next to useless :S
Cyclone
+1  A: 

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:

nevets1219
I am on 6.0.401.1 (Official Build 47018) dev, that might do it. I am trying to inject the code to the user page via extension, how can I do this? I can't use `chrome.tabs.executeScript`, it does not seem to want to inject favicon.js somehow.
Cyclone
I can't say I know much about Chrome extension, what have you done and what was the error? I will add some links that will be hopefully helpful.
nevets1219
I've figured out how to inject the code, but chrome://favicon/ isn't allowed to be accessed by my code. I gave up on the favicon.js file, it apparently has syntax errors or something. A friend seems to think that placing an img tag on the page with the favicon url will set the favicon, but I am not sure of the accuracy of that.
Cyclone
Maybe http://code.google.com/p/chromium/issues/detail?id=11854 will be helpful? It seems that whitelisting the favicon is required.
nevets1219
Can't do that, the favicon url is being placed on the page itself
Cyclone
Hm, I originally thought you wanted to change the favicon but this will be visible on the page? I'm not entirely sure what you are trying to accomplish now? If you want it on the page you can easily save that and reference it but you'll have to update it manually.
nevets1219
I am trying to change the favicon, yes.
Cyclone
Anything? I'd like to wrap this question up.
Cyclone
Can't say I know what other approach you could use. The best I can think of is to save the Chrome favicon and just try to use it so you don't have to depend on Chrome's resources.
nevets1219
A: 

ora mudeng, piye to, nek gawe tutorial mbok sing penak di mengerti to...

wiyono
What? In english please?
Cyclone