Make browser window blink in task Bar

JavascriptBrowser

Javascript Problem Overview


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.

Edit: These users do want to be distracted when a new message arrives.

Javascript Solutions


Solution 1 - Javascript

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.

newExcitingAlerts = (function () {
    var oldTitle = document.title;
    var msg = "New!";
    var timeoutId;
    var blink = function() { document.title = document.title == msg ? ' ' : msg; };
    var clear = function() {
        clearInterval(timeoutId);
        document.title = oldTitle;
        window.onmousemove = null;
        timeoutId = null;
    };
    return function () {
        if (!timeoutId) {
            timeoutId = setInterval(blink, 1000);
            window.onmousemove = clear;
        }
    };
}());

Update: You may want to look at using HTML5 notifications.

Solution 2 - Javascript

I've made a [jQuery plugin][1] 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.

Here is an example on how to use it:

$.titleAlert("New mail!", {
    requireBlur:true,
    stopOnFocus:true,
    interval:600
});

If you're not using jQuery, you might still want to look at the [source code][2] (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).

[1]: http://heyman.info/jquery-title-alert/ "jQuery Title Alert" [2]: http://github.com/heyman/jquery-titlealert "Source code at GitHub"

Solution 3 - Javascript

Supposedly you can do this on windows with the growl for windows javascript API:

http://ajaxian.com/archives/growls-for-windows-and-a-web-notification-api

Your users will have to install growl though.

Eventually this is going to be part of google gears, in the form of the NotificationAPI:

http://code.google.com/p/gears/wiki/NotificationAPI

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.

Solution 4 - Javascript

				var oldTitle = document.title;
				var msg = "New Popup!";
				var timeoutId = false;
				
				var blink = function() {
					document.title = document.title == msg ? oldTitle : msg;//Modify Title in case a popup
					
					if(document.hasFocus())//Stop blinking and restore the Application Title
					{
						document.title = oldTitle;
						clearInterval(timeoutId);
					}						
				};
				
				if (!timeoutId) {
					timeoutId = setInterval(blink, 500);//Initiate the Blink Call
				};//Blink logic	

Solution 5 - Javascript

My "user interface" response is: Are you sure your users want their browsers flashing, or do you think 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.

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.

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.

Solution 6 - Javascript

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.

Solution 7 - Javascript

Why not take the approach that GMail uses and show the number of messages in the page title?

Sometimes users don't want to be distracted when a new message arrives.

Solution 8 - Javascript

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.

document.title = "[user] hello world";

Solution 9 - Javascript

You may want to try window.focus() - but it may be annoying if the screen switches around

Solution 10 - Javascript

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.

Solution 11 - Javascript

function blinkTab() {
		const browserTitle = document.title;
		let timeoutId;
		let message = 'My New Title';
		
		const stopBlinking = () => {
			document.title = browserTitle;
			clearInterval(timeoutId);
		};
		
		const startBlinking = () => {
			document.title = document.title  === message ? browserTitle : message;
		};
		
		function registerEvents() {
			window.addEventListener("focus", function(event) { 
				stopBlinking();
			});
			
			window.addEventListener("blur", function(event) {
				const timeoutId = setInterval(startBlinking, 500);
			});
		};
		
		registerEvents();
	};


	blinkTab();

Solution 12 - Javascript

> These users do want to be distracted when a new message arrives.

It sounds like you're writing an app for an internal company project.

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.

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 :-)

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 :-(

Solution 13 - Javascript

"Make browser window blink in task Bar"

via Javascript 

is not possible!!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionerikView Question on Stackoverflow
Solution 1 - JavascriptnickfView Answer on Stackoverflow
Solution 2 - JavascriptheymanView Answer on Stackoverflow
Solution 3 - JavascriptJoeri SebrechtsView Answer on Stackoverflow
Solution 4 - JavascriptRikki GoswamiView Answer on Stackoverflow
Solution 5 - JavascriptRudiView Answer on Stackoverflow
Solution 6 - JavascriptRobin BarnesView Answer on Stackoverflow
Solution 7 - JavascriptandyukView Answer on Stackoverflow
Solution 8 - JavascriptToran BillupsView Answer on Stackoverflow
Solution 9 - JavascriptSugendranView Answer on Stackoverflow
Solution 10 - JavascriptChase SeibertView Answer on Stackoverflow
Solution 11 - JavascriptprashantsahniView Answer on Stackoverflow
Solution 12 - JavascriptOrion EdwardsView Answer on Stackoverflow
Solution 13 - JavascriptIngoView Answer on Stackoverflow