Emojis are awesome, so I was thinking how could add one as a favicon using link
tag.
One possible solution:
I found one possible way in this blog post here. Based on that it's been achieved what I wanted so far with the following solution.
JavaScript
code snippet:
const setFavicon = (emoji) => {
const canvas = document.createElement('canvas');
canvas.height = 32;
canvas.width = 32;
const ctx = canvas.getContext('2d');
ctx.font = '28px serif';
ctx.fillText(emoji, -2, 24);
const favicon = document.querySelector('link[rel=icon]');
if (favicon) { favicon.href = canvas.toDataURL(); }
}
setFavicon('π’');
The link
tag in HTML
:
<link rel="icon" type="image/png" href="favicon.ico"/>
So my question:
Maybe creating favicon.ico
file for this purpose would do the thing also. Is there any better way to achieve this without converting or having extra JavaScript
snippets in your code? Thank you!
y="32"
andfont-sizer="32"
, the rocket's edges were cut off. I mean, like if the emoji was bigger than the box holding it. Changed to 24 and now it renders fine. β Washwoman