Changing website favicon dynamically

前端 未结 15 1507
温柔的废话
温柔的废话 2020-11-22 02:17

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,

15条回答
  •  日久生厌
    2020-11-22 02:28

    If you have the following HTML snippet:

    
    

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

    You can also create a Canvas element and set the HREF as a ToDataURL() of the canvas, much like the Favicon Defender does.

提交回复
热议问题