📜  如何在 react js 中更改 favicon 动态 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:23.749000             🧑  作者: Mango

代码示例1
import React from "react";

function getFaviconEl() {
  return document.getElementById("favicon");
}

function App() {

  const handleGoogle = () => {
    const favicon = getFaviconEl(); // Accessing favicon element
    favicon.href = "https://www.google.com/favicon.ico";  };

  const handleYoutube = () => {
    const favicon = getFaviconEl();
    favicon.href = " https://s.ytimg.com/yts/img/favicon-vfl8qSV2F.ico";  };

  return (
    

Dynamically changing favicon

); } export default App;