Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

javascript - 动态更改网站图标(Changing website favicon dynamically)

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.(我有一个根据当前登录用户进行品牌标记的Web应用程序。我想将页面的图标更改为自有品牌的徽标,但是我找不到任何代码或任何示例,去做这个。)

Has anybody successfully done this before?(以前有人成功做到过吗?) 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.(我正在想象一个文件夹中有十二个图标,并且要使用的favicon.ico文件的引用是随HTML页面一起动态生成的。) Thoughts?(有什么想法吗?)   ask by SqlRyan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.(Firefox应该很棒。) edited to properly overwrite existing icons(编辑以正确覆盖现有图标)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...