js set the icon and title page

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 = ''; // Photo Address 
changeFavicon (icon); // dynamically modify the site icon 
the let title = ''; // Website title 
document.title = title; // dynamically modify the site title

 

Guess you like

Origin www.cnblogs.com/mary-123/p/12285008.html