开发者

How to write (number of notifications) in the address bar when a notification is found

开发者 https://www.devze.com 2023-02-07 06:13 出处:网络
Does any of you k开发者_高级运维now how most of the websites today show the number of notifications in the title bar when a new notification is found? Like if you have a notification on Facebook you g

Does any of you k开发者_高级运维now how most of the websites today show the number of notifications in the title bar when a new notification is found? Like if you have a notification on Facebook you get (1) Facebook in the title bar. How could I do that?


This uses simple Javascript. First, the title of the document is stored somewhere so when the title is written to multiple times, it doesn't prepend multiple (1)s to the title (i.e., you wouldn't want (3) (1) Facebook). Then it sets document.title to that original title while putting some bit of information on the front, something like this:

original_title = document.title

// time passes

document.title = "(" + update_count + ") " + original_title;


You can access the title bar by setting it explicitly:

document.title = document.title + ' (' + notificationCount+ ')'


If you mean the title bar, then you can use JavaScript:

var notifications = 2;
document.title = "("+ notifications +") ...";
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号