How does GMAIL have a favicon that shows an unread message count? [duplicate]
GMAIL in chrome has a favicon that shows an unread messag开发者_C百科e count. Does anyone know how they do that? Is that them changing images? Or is there a property that allows you to set the number near the favicon?
Thanks
I am not 100% certain on how Google accomplishes this however, someone created a UserScript to mimic the functionality. You can view the source code of this script and see how they accomplished it.
http://userscripts.org/scripts/review/39432
EDIT
I'm including this resource since userscripts is no longer around:
http://lab.ejci.net/favico.js/
on github
https://github.com/ejci/favico.js
They use different images for counter icons, They have one default favicon and use javascript to update as new email arrives.
e.g.
https://mail.google.com/mail/u/1/images/2/unreadcountfavicon/0.pnghttps://mail.google.com/mail/u/1/images/2/unreadcountfavicon/1.pnghttps://mail.google.com/mail/u/1/images/2/unreadcountfavicon/2.pnghttps://mail.google.com/mail/u/1/images/2/unreadcountfavicon/3.png
https://mail.google.com/mail/u/1/images/2/unreadcountfavicon/n.png
There's no property that sets a number next to the favicon, but you can change it in javascript. Check out this question Changing website favicon dynamically
I don't know how Google did it, but the way I did it way:
$('body').append($('<link rel="icon" type="image/ico" href="http://localhost/myfavicon.ico"/>'))
As needed.
I have no clue how they do it, but there's no reason you can't have your /faveicon.ico be responded to by a dynamic server-side script which generates/provides certain content based on information of the user in question.
That said... I don't think most browsers would get the updated Faveicon usually, as most seem to only check it once per session.
精彩评论