简体   繁体   English

如何设置图标以每天更改

[英]How to set a favicon to change daily

I have 8 favicons that need to change daily in a specific order. 我有8个图标需要每天按特定顺序进行更改。 The order will never change. 顺序永远不会改变。

If I titled my favicons: favicon1.png, favicon2.png ... etc, what is the best way to have the correct favicon pulled each day? 如果我将图标命名为favicon1.png,favicon2.png等,那么每天拉出正确图标的最佳方法是什么? Is this javascript? 这是JavaScript吗?

This page ( Can I change a favicon daily ) is regarding the same question, but after reading through it, I am still unsure how to correctly set it up. 该页面( 我可以每天更换一个Favicon图标 )是关于同一问题的,但是通读它之后,我仍然不确定如何正确设置它。 Furthermore, I read that to bypass the heavy caching, I need to move the images outside of the root directory. 此外,我读到要绕过繁重的缓存,我需要将映像移到根目录之外。 How is this done? 怎么做? I am using Ubuntu's Apache. 我正在使用Ubuntu的Apache。

Thank you in advance. 先感谢您。

var today=new Date(),
    day=today.getDay()+1,//from 1 to 7 (1 is sunday then monday...)
    link = document.querySelector("link[rel*='icon']") || document.createElement('link');

link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = 'urlPath/favicon'+day+'.png';
document.getElementsByTagName('head')[0].appendChild(link);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM