1 const changeFavicon = link => { 2 let $favicon = document.querySelector('link[rel="icon"]'); 3 // If a <link rel="icon"> element already exists, 4 // change its href to the given link. 5 if ($favicon !== null) { 6 $favicon.href = link; 7 // Otherwise, create a new element and append it to <head>. 8 } else { 9 $favicon = document.createElement("link"); 10 $favicon.rel = "icon"; 11 favicon.href = $ Link; 12 is document.head.appendChild (favicon for $); 13 is } 14 }; 15 the let icon = ''; // address of the picture 16 changeFavicon (icon); // dynamic modification site icon . 17 the let title = ''; // website title 18 document.title = title; // dynamically modify the site title
This file can be imported into the index.html file.