动态修改浏览器导航栏图标和文字

1、设置网站标题

let title = ""; // 网站标题
document.title = title; // 动态修改网站标题
let title = ""; // 网站标题
 document.querySelector('head title').innerText = title

2、设置网站图标

<link id="custom_favicon" rel="icon" href="" />
let icon = ""; //网站图标
document.getElementById('custom_favicon').href = icon
let icon = ""; //网站图标
changeFavicon(icon); // 动态修改网站图标

const changeFavicon = link => {
  let favicon = document.querySelector('link[rel="icon"]')
  if (favicon !== null) {
    favicon.href = link
  } else {
    favicon = document.createElement("link")
    favicon.rel = "icon"
    favicon.href = link
    document.head.appendChild(favicon)
  }
}
posted @ 2023-01-30 17:19  路暝月  阅读(101)  评论(0)    收藏  举报  来源