当用户在不同的选项卡中时,jQuery 更改页面的标题
我的页面上有实时聊天。 我想更改标题(使用像 omegle.com 中那样移动的内容)当收到新消息并且用户不在与实时聊天相同的选项卡中时。当用户返回选项卡时,标题将恢复正常。
我想这应该由 jQuery 来完成。您知道任何插件吗?或者我该怎么做?
I have live chat on my page. I want to change the title (with something moving like in omegle.com) when a new message is received and the user is not in the same tab as the live chat. When the user returns to the tab, the title would return to normal.
I guess it should be done by jQuery. Do you know any plugins or how can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
标题只能像这样编辑:
所以你可以这样做:
要使其闪烁,你必须使用
setTimeout()
; 做一些事情;Title can only be edited like so:
So you could do:
To make it flash you would have to do something with
setTimeout()
;尝试
Update
显然,在 IE 中,</code> 标记的内容,但您无法设置它的值,除非使用 <code>document.title</code>。我想这应该是对 jQuery API 的改进,因为 <code>$('title')[0]</code> 确实返回了 DOMElement (<code>nodeType = 1</code>)...
$('title')[0].innerHTML
返回try
Update
Apparantly, in IE,
$('title')[0].innerHTML
returns the content of the<title>
tag, but you can't set it's value, except usingdocument.title
. I guess this should be an improvement to the jQuery API, since$('title')[0]
does return a DOMElement (nodeType = 1
)...$('title').text('your title')
就足够了。要查看您是否采取了正确的路径,只需使用 IE 的开发人员工具栏 (F12) 并转到控制台并写入
$('title')
,您应该在控制台中看到 [...]。这意味着$('title')
是一个对象,并且一直有效。然后写入typeof $('title').text
,您应该会看到function
作为结果。如果这些测试都正常,那么你的 IE 就坏了。$('title').text('your title')
suffices.To see if you're taking the right path, simply use IE's developer toolbar (F12) and go to console and write
$('title')
, you should see [...] in console. This means that$('title')
is an object and it works up to here. Then writetypeof $('title').text
, and you should seefunction
as the result. If these tests are OK, then your IE is broken.