문제

I'm trying to find away to load a different favicon on page refresh/load. I've had a quick google but noting seems to be showing up in terms of tutorials.

도움이 되었습니까?

해결책

based on the answer from here: Changing website favicon dynamically I created what you want.

(function() {
    var arrFavicon = ['link_favicon1', 'link_favicon2', 'link_favicon3']; //put your favicon links here

    var link = document.createElement('link');
    link.type = 'image/x-icon';
    link.rel = 'shortcut icon';
    link.href = arrFavicon[Math.floor(Math.random()*arrFavicon.length)]; //don't need to change here no matter how many favicons you have
    document.getElementsByTagName('head')[0].appendChild(link);
}());

Now, all you have to do is put your favicons links inside the array arrFavicon and will automatically generate diferents favicons every time that the page is loaded.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top