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

change_icon() {
      const changeFavicon = link => {
        let $favicon = document.querySelector('link[rel="icon"]');
        // If a  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 .
        } else {
          $favicon = document.createElement("link");
          $favicon.rel = "icon";
          $favicon.href = link;
          document.head.appendChild($favicon);
        }
      };
      let icon = ""; // 图片地址
      changeFavicon(icon); // 动态修改网站图标
      let title = ""; // 网站标题
      document.title = title; // 动态修改网站标题
    }

 

你可能感兴趣的:(js,vue)