Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to change favicon dynamic in react js

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 (
    <div className="App">
      <h1>Dynamically changing favicon</h1>
      <button onClick={handleGoogle}>Google</button>      <button onClick={handleYoutube}>YouTube</button>    </div>
  );
}

export default App;
Comment

reactjs change favicon

1. Open the react app in your favorite code editor.
2. Navigate to the public folder and delete the favicon.ico file.
3. Now, add a new favicon inside the public folder.
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to prevent previous radio button active react native 
Javascript :: javascript Prevent Object MutationPassed 
Javascript :: react native better camera 
Javascript :: line graph view click event 
Javascript :: jquery check if click to this self not this child 
Javascript :: js string encode decode arabic 
Javascript :: list of javascript cheat sheet 
Javascript :: mapsort 
Javascript :: ab mob react native expo 
Javascript :: convert binary to string javascript 
Javascript :: mongoose fails to connect to server when database is specified 
Javascript :: react native onrefresh stuck release 
Javascript :: js array to scsv 
Javascript :: run strapi plugin at startup 
Javascript :: is javascript case sensitive 
Javascript :: stop monitorevents 
Javascript :: theme ui currentcolor 
Javascript :: express react docker container example 
Javascript :: dropzone not working when input is clicked 
Javascript :: sum of array odd number javascript 
Javascript :: nodejs store selected dropdown in variable 
Javascript :: how to include build script in node js 
Javascript :: js toggle opacity 
Javascript :: how add all json files to one json file in command prompt 
Javascript :: basketball socket io 
Javascript :: thunk sintaxe 
Javascript :: pdf javascript search text 
Javascript :: train function ajax 
Javascript :: what is code.jquery integrity crossorigin 
Javascript :: how to create monorapo project in angular 8 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =