javascript 让我的浏览器闪烁作为指示器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3469337/
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
make my browser blink as indicator
提问by Rod
My coworker wrote a quick mvc chat application so we can chat about work stuff without leaving our desks.
我的同事编写了一个快速的 mvc 聊天应用程序,这样我们就可以在不离开办公桌的情况下聊聊工作上的事情。
What are some ways to indicate to each other a new message has been posted? My first thought was make the browser title bar flash. Anyone know how?
有哪些方法可以向对方表明已发布新消息?我的第一个想法是让浏览器标题栏闪烁。有谁知道怎么做?
回答by jorgebg
It is not possible to make the browser blink in javascript. A possibility is to set the document title to empty an then write it again with through a period of time with setTimeout()
无法在 javascript 中使浏览器闪烁。一种可能性是将文档标题设置为空,然后使用setTimeout()在一段时间内再次写入
回答by Peter Ajtai
You could play a tone or other audio clipwhen a new message displays.
您可以在显示新消息时播放提示音或其他音频剪辑。
The nice thing about an audible cue is that you are able to keep your eyes on your work until you come to a natural break point to answer the message. Visual cues, in my opinion, are more likely to interrupt your work flow.
声音提示的好处在于,您可以将注意力集中在工作上,直到自然而然地停下来回答消息。在我看来,视觉提示更有可能打断你的工作流程。
Obviously you can make the audible cue as pleasant and non-intrusive as your imagination allows.
显然,您可以在您的想象力允许的范围内使可听提示变得令人愉悦且不受干扰。
回答by heyman
I've written a jQuery pluginfor this purpose. See my answerto this question.
回答by tcooc
This nifty function i got reserved should be handy:
我保留的这个漂亮的功能应该很方便:
It changes the title of the page to alert the user, and returns the function that will stop the interval(i.e. on a window.onmousemovelistener).
它更改页面标题以提醒用户,并返回将停止间隔的函数(即在window.onmousemove侦听器上)。
function Alert(msg [, ti]) {
// msg = the message, ti= time interval between title changes(default is 1.5s)
var intervalId, oldTitle = document.title;
intervalId = setInterval(function(){
document.title = document.title == msg ? oldTitle : msg;
}, ti ? ti : 1500);
return function() {
if(oldTitle) {
clearInterval(intervalId);
document.title = oldTitle;
oldTitle = intervalId = null;
}
};
}

