1. Web Design
  2. UX/UI
  3. UX Design

How to Display Update Notifications in the Browser Tab

Scroll to top

Websites and web apps with frequently updated content have to figure out a way to grab users’ attention to tell them of updates, particularly where users may have moved away from the tab where the website or app is active. 

There are a couple of common patterns which you’ll see out in the wild. Social websites such as Facebook, Twitter, and LinkedIn, which potentially receive new content every few seconds, insert the relevant number into the page title showing the amount of new updates in the tab. Trello, on the other hand, shows a tiny red badge on the favicon.

Trello Facebook and Twitter notificationsTrello Facebook and Twitter notificationsTrello Facebook and Twitter notifications
Trello, Facebook and Twitter notifications

In this tutorial, we are going to replicate this form of feedback design, making use of the browser tab as a medium for notifying users of updates. Check out the demo then let’s see how it’s done.

Using the Document Title

We’ll begin by appending the number of new updates to the page title, similar to how Facebook and Twitter do.

In a real world scenario we might retrieve data in any number of ways (talk to your friendly developer). In this case, we’ll assume that we’ve retrieved the number of updates and have the figure available to us to play with in JavaScript. For now, it appears that we currently have zero updates, so we’ll pass that number to a variable:

1
var count = 0;

The next will be the meat of our code where we will alter the document title. First of all, we add document.title which will retrieve our current document title:

1
var title = document.title;

Then we create a new function to change the string within that title:

1
function changeTitle() {
2
	count++;
3
	var newTitle = '(' + count + ') ' + title;
4
	document.title = newTitle;
5
}

Here you can see that we use the JavaScript ++ operator. For the purposes of our demonstration the ++ will increase our count number by 1 for each iteration. As we started off with 0, the next iteration will return 1. We use the ++ operator to simulate the number increment, since we do not have access to an API to feed us with a real number.

Next we create another new function that will run the changeTitle() function:

1
function newUpdate() {
2
	update = setInterval(changeTitle, 2000);
3
}
4
var docBody = document.getElementById('site-body');
5
docBody.onload = newUpdate;

The above function assumes that we need to check for new updates every 2000 milliseconds (2 seconds). Our function, changeTitle(), will continuously run within the interval. We run this function as soon as the page is loaded.

The first method is quite straightforward. We retrieve the number and pass it in the title. You may change the brackets that wrap the number from ( ) to [ ] or { } by changing them in the changeTitle() function.

Using the Favicon

Now we are going to try the second approach, which is to change the favicon like the Trello web app does. For this, we will need to prepare two favicon variants, where the second variant is the alternative that we will display whenever we received new updates.

Begin by linking the first favicon within the document.

1
<link id="favicon" rel="icon" href="img/favicon.gif?v3"/>

Then set the path of the new favicon in a JavaScript variable.

1
var iconNew = 'img/favicon-dot.gif';

As with the first approach, we will also create two functions:

1
function changeFavicon() {
2
	document.getElementById('favicon').href = iconNew;
3
}
4
function newUpdate() {
5
	update = setInterval(changeFavicon, 3000);
6
	setTimeout(function() { 
7
		clearInterval( update ); 
8
	}, 3100);
9
}
10
11
var docBody = document.getElementById('site-body');
12
docBody.onload = newUpdate;

The first function, changeFavicon(), will replace our initial favicon with the one with the red badge. The second function, newUpdate(), will execute the first function within the specified time.

It seems there is something new to look at!

The second approach is not as complicated as you may have first thought; it is, in fact, simpler than the first one where we updated the page title string. Additionally, we can pour more creativity into the alternate favicon. For example, we could make the red badge blinking rather than still (be careful now..), or perhaps change the entire favicon color and icon.

Note: Chrome does not support favicons with animated GIF.

Using Favico.js

To finish off, we are now going to use a JavaScript library called Favico.js, developed by Miroslav Magda. The library provides a handy API with tons of options to alter the favicon such as showing a badge along with the number of updates all together.

To begin with, using JavaScript, we define a new Favico instance which defines the badge position, animation, the background color as well as the text color.

1
var favicon = new Favico({
2
	position  :'up',
3
	animation :'popFade',
4
	bgColor   :'#dd2c00',
5
	textColor :'#fff0e2'
6
});

Then we add a couple of functions to run this new instance and ultimately show the badge in the favicon.

1
var num = 0;
2
function generateNum() {
3
	num++;
4
	return num;
5
}
6
7
function showFaviconBadge() {
8
	var num = generateNum();
9
	favicon.badge(num);	
10
}
11
12
function newUpdate() {
13
	update = setInterval(showFaviconBadge, 2000);
14
}
15
16
var docBody  = document.getElementById('site-body');
17
docBody.onload = newUpdate;

The code somewhat resembles the first method we did earlier. We begin with creating the function that will simulate the number of updates that we will show within the badge. The second function, showFaviconBadge(), is to insert the number into the badge and show the badge in the favicon. The last function newUpdate() will run the second function within the specified time interval, giving us a sense of receiving new updates.

Conclusion

In this tutorial, we have used the browser tab as a medium to notify users. We have replicated methods that are commonly applied in popular websites like Facebook, Twitter, and Trello along with evaluating their limitations.

Again, you’ll probably have to make a couple of changes to make this fit it in your particular web application, but the examples here give you a great start!

Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Web Design tutorials. Never miss out on learning about the next big thing.
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.