Jump to content

Changing icon dynamically


bPHP

Recommended Posts

I'm trying to change my shortcut icon dynamically but it is not working. Firebug shows that the change was made, however the page does not change the icon.

 

Here is what I have:

 

if (updated === true) {
	if (loopingNum % 2 === 0) {
		document.title = 'You have updates __';
		setIcon('../img/icon.png');
	} else {
		document.title = 'You have updates  _-';
		setIcon('../img/icon2.png');
	}
	loopingNum++;}

 

My setIcon function:

 

function setIcon(path) {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	if(a.getAttribute("rel").indexOf("SHORTCUT ICON") != -1) {
	a.setAttribute('href', path);		
 }
  }
  return null;
}

 

The title is changed dynamically but the icon does not change... What am I missing?

 

Thanks!

Link to comment
Share on other sites

Using that code won't work GB_001. They are trying to change the favicon for the page, not an <img /> tag.

 

I recommend you look at this: http://ajaxify.com/run/favicon/

 

Should be a quick solution for you

 

It also seems that changing the favicon dynamically in JavaScript will only work for Firefox and Opera (maybe Chrome too). But I know IE and Safari do not support it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.