简体   繁体   中英

How to set a favicon to change daily

I have 8 favicons that need to change daily in a specific order. 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? Is this 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. 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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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