0

I am writing a java script code which is going to change the fav icons for webpages. I am able to do it successfully for most of the webpages a/c to situation. But the webpages which doesn't have fav icons are caching the fav icon my code is setting and then the only way to remove icon is clearing the cache. Is there any way by which I can add my fav icon to the page without letting it cached.

var links = docHead.getElementsByTagName('link');
for (var i=0; i<links.length; i++) {
    var olink = links[i];
    if (olink.rel != null && olink.rel != undefined && (olink.rel.indexOf('icon') != -1)) {
        docHead.removeChild(olink);
    }
}
var link = document.createElement('link');
link.rel = 'icon';
link.href = **---- link for my fav icon ---------**
docHead.appendChild(link);

So , what this piece of code is doing, if a webpage is having some fav icon , its removing it and replacing it with my fav icon and on refresh its again getting its original fav icon.

SHASHA
  • 90
  • 1
  • 12

1 Answers1

0

You can add a generated parameter to your fav icon URL like

http://url.to.my.fav.icon?v=ad3r4as

So everytime you change the value of that parameter, the browser treat it like a new image.

Eytibi
  • 545
  • 6
  • 12