How to force ie11 to request a new favicon?

后端 未结 4 1617
清歌不尽
清歌不尽 2021-01-15 03:01

I am working on a website which changes its favicon depending on the user details logged in. A controller processes this request at the back-end and sends the appropriate fa

4条回答
  •  野的像风
    2021-01-15 04:00

    Using JavaScript to change the favicon in IE11:

    HTML

    
    

    JS

    // Chrome allows you to simply tweak the HREF of the LINK tag.
    // Firefox appears to require that you remove it and readd it.
    function setFavicon(url)
    {
        removeFavicon();
        var link=document.createElement('link');
        link.type='image/x-icon';
        link.rel='icon';
        link.href=url;
        document.getElementsByTagName('head')[0].appendChild(link);
        if (window.console) console.log("Set FavIcon URL to " + getFavicon().href);
     }
    
    function removeFavicon()
    {
        var links=document.getElementsByTagName('link');
        var head=document.getElementsByTagName('head')[0];
        for(var i=0; i

    Demo: http://www.enhanceie.com/test/favicon/dynamic.htm

    NOTE: This works in Chrome, Firefox, IE11+. It doesn't work in IE10 or earlier, Opera 12.15, or Safari 6.0.5(mac). Combine this method with your favicon.ico?v=xxxx method for earlier browsers.

提交回复
热议问题