发现通知时如何在地址栏中写入(通知数量)
你们中有人知道当今大多数网站在发现新通知时如何在标题栏中显示通知数量吗?就像如果您在 Facebook 上收到通知一样,您会在标题栏中看到 (1) Facebook。我怎么能这么做呢?
Does any of you know 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这使用简单的 Javascript。首先,文档的标题存储在某处,因此当标题被多次写入时,它不会在标题前面添加多个
(1)
(即,您不希望(3) (1) Facebook
)。然后它将document.title
设置为原始标题,同时在前面放置一些信息,如下所示: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 setsdocument.title
to that original title while putting some bit of information on the front, something like this:您可以通过显式设置来访问标题栏:
You can access the title bar by setting it explicitly:
如果你指的是标题栏,那么你可以使用 JavaScript:
If you mean the title bar, then you can use JavaScript: