How to Change Favicon with JavaScript


This code comes in handy when you don’t have access to the head of the page and need to change the favicon.

(function() {
    var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
    link.type = 'image/x-icon';
    link.rel = 'shortcut icon';
    link.href = 'https://yourdomain.com/favicon.ico';
    document.getElementsByTagName('head')[0].appendChild(link);
})();

 



Written by: Jake Lett
I share digital marketing tips and HubSpot tutorials to help marketers and business owners grow their business.

Topic:

Related posts

Tags:

Want to Get Email Updates of New Articles?

Join My Email Newsletter