How to Change Favicon with JavaScript

Download FREE Marketing Guides

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.


Related posts

Tags:

Want to Get Email Updates of New Articles?

Join My Email Newsletter