bPHP Posted April 23, 2010 Share Posted April 23, 2010 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! Quote Link to comment Share on other sites More sharing options...
GB_001 Posted April 27, 2010 Share Posted April 27, 2010 Why don't you try document.getElementById('imageID').src="/newimage.gif";? Quote Link to comment Share on other sites More sharing options...
de.monkeyz Posted April 27, 2010 Share Posted April 27, 2010 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.