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 :: react native scrollbar position issue 
Javascript :: onsubmit in reactjs 
Javascript :: how get height elemnt with that margin in js 
Javascript :: filter array of objects with array of objects 
Javascript :: scroll to element in scrollable div 
Javascript :: javascript mouse over and mouse enter 
Javascript :: javascript check string lenght 
Javascript :: remove empty option from bootstrap select javascript 
Javascript :: add two numbers in javascript 
Javascript :: how to get a particular line from a file in nodejs 
Javascript :: themein material ui 
Javascript :: javascript code for line break after comma 
Javascript :: momentjs utcoffset 
Javascript :: js for loops 
Javascript :: round innerhtml value up javascript 
Javascript :: vue 3 route params 
Javascript :: object literal javascript 
Javascript :: vue 3 router alias 
Javascript :: eslint disable tag 
Javascript :: firebase auth api key not valid. please pass a valid api key 
Javascript :: get audio duration node js 
Javascript :: javjquery is emptyobject 
Javascript :: how to add base url as src in react native 
Javascript :: creating 2d array in javascript 
Javascript :: how to check string uppercase or lowersace using regex javascript 
Javascript :: api.fetch saga 
Javascript :: how to get all attributes of an element in jquery 
Javascript :: lodash swap array elements 
Javascript :: Error occurred while trying to proxy to: localhost:3000/ 
Javascript :: javascript play audio from buffer 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =