如何强制ie11请求一个新的网站图标? [英] How to force ie11 to request a new favicon?

查看:49
本文介绍了如何强制ie11请求一个新的网站图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个网站上,该网站会根据登录的用户详细信息来更改其图标。控制器在后端处理此请求,并为该站点发送适当的图标。到目前为止,我避免了大多数浏览器通过以下方式访问收藏夹图标:

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 favicon for the site. So far, I avoided the favicon getting cached by most browsers through this:

<link rel="shortcut icon" type="image/x-icon" href="resources/favicon.ico?v=${date.time}"/>

但是,该图标仍被缓存在ie11中。当我在Netbeans上打开调试时,控制器未收到任何请求。

However, the favicon still gets cached in ie11. No requests were received by the controller when I turned on debug on Netbeans.

注意事项:


  1. 进入站点后的第一个收藏夹起作用。登录后,我只是无法替换

  2. 我在地址栏中输入了收藏夹网址,并返回了正确的收藏夹图标。

我一直在四处寻找,但找不到解决该问题的方法。 :<

I've been looking around but I can't find a solution to this problem. :<

推荐答案

使用JavaScript更改IE11中的收藏夹图标:

Using JavaScript to change the favicon in IE11:

HTML

<link rel="icon" type="image/x-icon" href="resources/favicon.ico">

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<links.length; i++)
    {
        if(links[i].getAttribute('rel')==='icon'){
             head.removeChild(links[i])
        }         
    }      
}

演示: http://www.enhanceie.com/test/favicon /dynamic.htm

注意:该功能适用​​于Chrome,Firefox,IE11 +。在IE10或更早版本,Opera 12.15或Safari 6.0.5(mac)中不起作用。对于较早的浏览器,请将此方法与favicon.ico?v = xxxx方法结合使用。

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.

这篇关于如何强制ie11请求一个新的网站图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆