Created
January 13, 2019 13:59
-
-
Save maidis/f5f91090aeae75d7bc47a229f74f3b2d to your computer and use it in GitHub Desktop.
Favicon Olarak Emoji
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <link rel="icon" data-emoji="🛰" type="image/png"> | |
| <body> | |
| <h2>JavaScript ile Emojileri Favicon Olarak Kullanın</h2> | |
| <p>Siz de mi favicon.ico oluşturmaktan sıkıldınız?</p> | |
| <p id="demo"></p> | |
| <script> | |
| const favicon = document.querySelector("link[rel=icon]"); | |
| if (favicon) { | |
| const emoji = favicon.getAttribute("data-emoji"); | |
| if (emoji) { | |
| const canvas = document.createElement("canvas"); | |
| canvas.height = 64; | |
| canvas.width = 64; | |
| const ctx = canvas.getContext("2d"); | |
| ctx.font = "64px serif"; | |
| ctx.fillText(emoji, 0, 64); | |
| favicon.href = canvas.toDataURL(); | |
| } | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment