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

  • Post author:
  • Post category:其他


change_icon() {
      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; // 动态修改网站标题
    }



版权声明:本文为wodebokecsdn原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。