Changing website favicon dynamically

前端 未结 15 1331
温柔的废话
温柔的废话 2020-11-22 02:17

I have a web application that\'s branded according to the user that\'s currently logged in. I\'d like to change the favicon of the page to be the logo of the private label,

15条回答
  •  攒了一身酷
    2020-11-22 02:23

    Why not?

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

    Firefox should be cool with it.

    edited to properly overwrite existing icons

提交回复
热议问题