Changing website favicon dynamically

前端 未结 15 1601
温柔的废话
温柔的废话 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

    Or if you want an emoticon :)

    var canvas = document.createElement("canvas");
    canvas.height = 64;
    canvas.width = 64;
    
    var ctx = canvas.getContext("2d");
    ctx.font = "64px serif";
    ctx.fillText("☠️", 0, 64); 
    
    $("link[rel*='icon']").prop("href", canvas.toDataURL());
    

    Props to https://koddsson.com/posts/emoji-favicon/

提交回复
热议问题