动态改变网站图标 [英] Changing website favicon dynamically

查看:142
本文介绍了动态改变网站图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个根据用户登录的网络应用程序,我想将页面的图标改为私人标签的标识,但是我找不到任何代码或任何代码如何做到这一点的例子。有没有人成功完成了这个?

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, but I'm unable to find any code or any examples of how to do this. Has anybody successfully done this before?

我在一个文件夹中打了十几个图标,并且使用哪个favicon.ico文件的引用只是动态地生成与HTML页面。想法?

I'm picturing having a dozen icons in a folder, and the reference to which favicon.ico file to use is just generated dynamically along with the HTML page. Thoughts?

推荐答案

为什么不?

(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应该很酷。

Firefox should be cool with it.

编辑以正确覆盖现有图标

这篇关于动态改变网站图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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