To add a browser tab icon using JavaScript, you can use the following code:
var icon = document.createElement('link');
icon.setAttribute('rel', 'shortcut icon');
icon.setAttribute('type', 'image/png');
icon.setAttribute('href', 'path/to/icon.png');
document.head.appendChild(icon);
In this code snippet, you create a new link
element with the shortcut icon
relation and set the type
to image/png
. Then, you set the href
attribute to the path of the icon file. Finally, you append the new element to the head
of the document.
Asked: 2022-09-12 11:00:00 +0000
Seen: 7 times
Last updated: May 31 '22