当用户更改主题时,是否可以更改网站上的网站图标?

问题描述:

我在我的网站上有两个主题:红色和蓝色。这工作正常...

i have 2 themes on my site: Red, and Blue. This works fine...

我必须知道,如果我可以做一些更改图标,当用户更改主题...

i must know if i can make something to change the favicon, when users change theme...

我知道这个代码是用于实现favicon:

i know this code is for implement favicon:

<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" href="favicon.ico" />

所以我需要使这个可能吗?使用jQuery?

so.. what i need to make this possible? using jQuery?

我有这个脚本,我用于更改主题:

i have this script, that i use for change themes:

$("#painel_faccao li a").click(function() { 
        $("link#faccao").attr("href",$(this).attr('rel'));      
        $.cookie("css",$(this).attr('rel'), {expires: 365, path: '/'});
     return false;

  });

如何实现这里?

(这个问题有一个更现代的方法这个函数)

(This question has a more modern approach to this function)

Stack Overflow这里有一个答案: a href =http://stackoverflow.com/questions/260857/changing-website-favicon-dynamically>动态更改网站图标

There is an answer on here on Stack Overflow: Changing website favicon dynamically

我喜欢此答案最好:

如果您有以下HTML代码段:

If you have the following HTML snippet:

<link id="favicon" rel="shortcut icon" type="image/png" href="favicon.png" />

您可以通过更改此链接上的HREF元素使用Javascript更改图标,例如're use JQuery):

You can change the favicon using Javascript by changing the HREF element on this link, for instance (assuming you're using JQuery):

$("#favicon").attr("href","favicon2.png");

只需使用JQuery检查样式表并根据它更改图标。

Just use JQuery to check the stylesheet and change the favicon based on it.