I'd like to change my favicon and browser tab text when a user navigates away to another browser tab. Does anyone know of a simple way to do this?
Asked
Active
Viewed 2,764 times
2 Answers
1
Use the window.onblur
event to change document.title
and the favicon. Changing favicons in some browsers can be tricky. See stackoverflow.com/questions/260857/changing-website-favicon-dynamically/260876#260876 for more info.
window.onblur=function(){
//change favicon
document.title="bye";
}
window.onfocus=function(){
document.title="hello";
}

Community
- 1
- 1

sudo rm -rf slash
- 1,156
- 2
- 16
- 27
0
The simplest way to achieve this would be to use javascript to detect if the tab is active:
How to tell if browser/tab is active
Start with this next line in your <head></head>
<link rel="shortcut icon" id="changingFavicon" type="image/png" href="/favicon.png"/>
Using the javascript example linked above to check if the tab is no longer active change the href to the new directory location like so using jquery.
$("#changingFavicon").attr("href", "http://newlocation.com/favicon.png");