javascript 在任务栏浏览器选项卡上显示自定义文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9247722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Showing custom text on the taskbar browser tab
提问by Istiaque Ahmed
For example suppose you have 3 notifications in Facebook.
例如,假设您在 Facebook 中有 3 个通知。
When you open the website, you see a browser tab (?) on the taskbar showing '(3) Your name' in Chrome or '(3)Facebook- Mozilla...' in Firefox.
当您打开网站时,您会在任务栏上看到一个浏览器选项卡 (?),在 Chrome 中显示“(3) 您的姓名”或在 Firefox 中显示“(3)Facebook- Mozilla...”。
For a webpage, the title value (plus browser dependent text) is shown as text in the browser tab and on the taskbar.
对于网页,标题值(加上浏览器相关文本)在浏览器选项卡和任务栏上显示为文本。
How can I add the number of notifications (i.e. 3 here) there? Is it done with HTML, JavaScript or what?
我如何在那里添加通知数量(即 3 条)?它是用 HTML、JavaScript 还是什么完成的?
回答by daniel
The contents of the title could either be set by the default HTML originating from the server-side in the <title></title>
element, or it could be set using the document.title
property in Javascript.
标题的内容可以由<title></title>
元素中源自服务器端的默认 HTML 设置,也可以使用document.title
Javascript 中的属性设置。
回答by Gareth
Well you answered most of this question yourself.
你自己回答了这个问题的大部分。
The missing piece of the puzzle is that you can change the page title dynamically using javascript:
缺少的部分是您可以使用 javascript 动态更改页面标题:
document.title = "(2) New title"