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
https://forums.phpfreaks.com/topic/199507-changing-icon-dynamically/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.