<p>How do I make a user's browser blink/flash/highlight in the task bar using JavaScript? For example, if I make an AJAX request every 10 seconds to see if the user has any new messages on the server, I want the user to know it right away, even if he is using another application at the time.</p>

<p><em>Edit: These users do want to be distracted when a new message arrives.</em></p>

[{'answer_id': 37134, 'author': 'Robin Barnes', 'author_id': 1349865, 'author_profile': 'https://Stackoverflow.com/users/1349865', 'pm_score': 2, 'selected': False, 'text': "<p>The only way I can think of doing this is by doing something like alert('you have a new message') when the message is received. This will flash the taskbar if the window is minimized, but it will also open a dialog box, which you may not want.</p>\n"}, {'answer_id': 37163, 'author': 'andyuk', 'author_id': 2108, 'author_profile': 'https://Stackoverflow.com/users/2108', 'pm_score': 2, 'selected': False, 'text': "<p>Why not take the approach that GMail uses and show the number of messages in the page title?</p>\n\n<p>Sometimes users don't want to be distracted when a new message arrives.</p>\n"}, {'answer_id': 37233, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': -1, 'selected': False, 'text': "<blockquote>\n  <p><i>These users do want to be distracted when a new message arrives.</i></p>\n</blockquote>\n\n<p>It sounds like you're writing an app for an internal company project. </p>\n\n<p>You might want to investigate writing a small windows app in .net which adds a notify icon and can then do fancy popups or balloon popups or whatever, when they get new messages.</p>\n\n<p>This isn't overly hard and I'm sure if you ask SO 'how do I show a tray icon' and 'how do I do pop up notifications' you'll get some great answers :-)</p>\n\n<p>For the record, I'm pretty sure that (other than using an alert/prompt dialog box) you can't flash the taskbar in JS, as this is heavily windows specific, and JS really doesn't work like that. You may be able to use some IE-specific windows activex controls, but then you inflict IE upon your poor users. Don't do that :-(</p>\n"}, {'answer_id': 37283, 'author': 'Toran Billups', 'author_id': 2701, 'author_profile': 'https://Stackoverflow.com/users/2701', 'pm_score': 1, 'selected': False, 'text': '<p>you could change the title of the web page with each new message to alert the user. I did this for a browser chat client and most users thought it worked well enough. </p>\n\n<pre><code>document.title = "[user] hello world";\n</code></pre>\n'}, {'answer_id': 156250, 'author': 'Rudi', 'author_id': 22830, 'author_profile': 'https://Stackoverflow.com/users/22830', 'pm_score': 2, 'selected': False, 'text': '<p>My "user interface" response is: Are you sure <em>your users</em> want their browsers flashing, or do <em>you think</em> that\'s what they want? If I were the one using your software, I know I\'d be annoyed if these alerts happened very often and got in my way.</p>\n\n<p>If you\'re sure you want to do it this way, use a javascript alert box. That\'s what Google Calendar does for event reminders, and they probably put some thought into it.</p>\n\n<p>A web page really isn\'t the best medium for need-to-know alerts. If you\'re designing something along the lines of "ZOMG, the servers are down!" alerts, automated e-mails or SMS messages to the right people might do the trick.</p>\n'}, {'answer_id': 156272, 'author': 'Sugendran', 'author_id': 22466, 'author_profile': 'https://Stackoverflow.com/users/22466', 'pm_score': 1, 'selected': False, 'text': '<p>You may want to try window.focus() - but it may be annoying if the screen switches around</p>\n'}, {'answer_id': 156274, 'author': 'nickf', 'author_id': 9021, 'author_profile': 'https://Stackoverflow.com/users/9021', 'pm_score': 7, 'selected': True, 'text': '<p>this won\'t make the taskbar button flash in changing colours, but the title will blink on and off until they move the mouse. This should work cross platform, and even if they just have it in a different tab.</p>\n\n<pre><code>newExcitingAlerts = (function () {\n    var oldTitle = document.title;\n    var msg = "New!";\n    var timeoutId;\n    var blink = function() { document.title = document.title == msg ? \' \' : msg; };\n    var clear = function() {\n        clearInterval(timeoutId);\n        document.title = oldTitle;\n        window.onmousemove = null;\n        timeoutId = null;\n    };\n    return function () {\n        if (!timeoutId) {\n            timeoutId = setInterval(blink, 1000);\n            window.onmousemove = clear;\n        }\n    };\n}());\n</code></pre>\n\n<hr>\n\n<p><em>Update</em>: You may want to look at using <a href="https://paulund.co.uk/how-to-use-the-html5-notification-api" rel="noreferrer">HTML5 notifications</a>.</p>\n'}, {'answer_id': 156316, 'author': 'Joeri Sebrechts', 'author_id': 20980, 'author_profile': 'https://Stackoverflow.com/users/20980', 'pm_score': 3, 'selected': False, 'text': '<p>Supposedly you can do this on windows with the growl for windows javascript API:</p>\n\n<p><a href="http://ajaxian.com/archives/growls-for-windows-and-a-web-notification-api" rel="nofollow noreferrer">http://ajaxian.com/archives/growls-for-windows-and-a-web-notification-api</a></p>\n\n<p>Your users will have to install growl though.</p>\n\n<p>Eventually this is going to be part of google gears, in the form of the NotificationAPI:</p>\n\n<p><a href="http://code.google.com/p/gears/wiki/NotificationAPI" rel="nofollow noreferrer">http://code.google.com/p/gears/wiki/NotificationAPI</a></p>\n\n<p>So I would recommend using the growl approach for now, falling back to window title updates if possible, and already engineering in attempts to use the Gears Notification API, for when it eventually becomes available.</p>\n'}, {'answer_id': 160617, 'author': 'Chase Seibert', 'author_id': 7679, 'author_profile': 'https://Stackoverflow.com/users/7679', 'pm_score': 0, 'selected': False, 'text': '<p>AFAIK, there is no good way to do this with consistency. I was writing an IE only web-based IM client. We ended up using window.focus(), which works most of the time. Sometimes it will actually cause the window to steal focus from the foreground app, which can be really annoying.</p>\n'}, {'answer_id': 3886467, 'author': 'heyman', 'author_id': 27406, 'author_profile': 'https://Stackoverflow.com/users/27406', 'pm_score': 6, 'selected': False, 'text': '<p>I\'ve made a <a href="http://heyman.info/jquery-title-alert/" rel="noreferrer" title="jQuery Title Alert">jQuery plugin</a> for the purpose of blinking notification messages in the browser title bar. You can specify different options like blinking interval, duration, if the blinking should stop when the window/tab gets focused, etc. The plugin works in Firefox, Chrome, Safari, IE6, IE7 and IE8.</p>\n\n<p>Here is an example on how to use it:</p>\n\n<pre><code>$.titleAlert("New mail!", {\n    requireBlur:true,\n    stopOnFocus:true,\n    interval:600\n});\n</code></pre>\n\n<p>If you\'re not using jQuery, you might still want to look at the <a href="http://github.com/heyman/jquery-titlealert" rel="noreferrer" title="Source code at GitHub">source code</a> (there are a few quirky bugs and edge cases that you need to work around when doing title blinking if you want to fully support all major browsers).</p>\n'}, {'answer_id': 31615360, 'author': 'Rikki Goswami', 'author_id': 5153189, 'author_profile': 'https://Stackoverflow.com/users/5153189', 'pm_score': 3, 'selected': False, 'text': '<pre><code>                var oldTitle = document.title;\n                var msg = "New Popup!";\n                var timeoutId = false;\n\n                var blink = function() {\n                    document.title = document.title == msg ? oldTitle : msg;//Modify Title in case a popup\n\n                    if(document.hasFocus())//Stop blinking and restore the Application Title\n                    {\n                        document.title = oldTitle;\n                        clearInterval(timeoutId);\n                    }                       \n                };\n\n                if (!timeoutId) {\n                    timeoutId = setInterval(blink, 500);//Initiate the Blink Call\n                };//Blink logic \n</code></pre>\n'}, {'answer_id': 57670498, 'author': 'prashantsahni', 'author_id': 1076982, 'author_profile': 'https://Stackoverflow.com/users/1076982', 'pm_score': 0, 'selected': False, 'text': '<pre><code>function blinkTab() {\n        const browserTitle = document.title;\n        let timeoutId;\n        let message = \'My New Title\';\n\n        const stopBlinking = () =&gt; {\n            document.title = browserTitle;\n            clearInterval(timeoutId);\n        };\n\n        const startBlinking = () =&gt; {\n            document.title = document.title  === message ? browserTitle : message;\n        };\n\n        function registerEvents() {\n            window.addEventListener("focus", function(event) { \n                stopBlinking();\n            });\n\n            window.addEventListener("blur", function(event) {\n                const timeoutId = setInterval(startBlinking, 500);\n            });\n        };\n\n        registerEvents();\n    };\n\n\n    blinkTab();\n</code></pre>\n'}, {'answer_id': 66188187, 'author': 'Ingo', 'author_id': 2278668, 'author_profile': 'https://Stackoverflow.com/users/2278668', 'pm_score': -1, 'selected': False, 'text': '<p>&quot;Make browser window blink in task Bar&quot;</p>\n<pre><code>via Javascript \n</code></pre>\n<p>is not possible!!</p>\n'}]
['https://Stackoverflow.com/questions/37122', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1191/']