const changeFavicon = link => { let $favicon = document.querySelector('link[rel="icon"]'); // If a <link rel="icon"> element already exists, // change its href to the given link. if ($favicon !== null) { $favicon.href = link; // Otherwise, create a new element and append it to <head>. } else { $favicon = document.createElement("link"); $favicon.rel = "icon"; $favicon.href = link; document.head.appendChild($favicon); } }; let icon = ''; // 圖片地址 changeFavicon(icon); // 動態修改網站圖標 let title = ''; // 網站標題 document.title = title; // 動態修改網站標題