Unleash the Power of Popups

Taming Annoying Popups

There is nothing more annoying than browsing a website and having a new window popup after ever page view. If you only had to deal with one popup, and that's it, it isn't so annoying. So one way to make popups less annoying is to limit their display. You could do one a day, one a session, or just once per person forever. If your regular visitors are already familiar with your products or services then using a popup that only displays once for each person forever will be a good way to introduce new visitors to your products without annoying regular visitors.

You can accomplish this kind of limitation using Javascript and cookies. Additionally you can use those same tools to change how your popups appear. For instance for a demographic survey you may not want the popup appearing on a user's first view as they might not be part of your core demographic. So you might popup a window after their tenth view so that you can be more sure that they are genuinely interested in your subject matter.

You can also decide if you want to popup a window when the page loads, or when it unloads. For instance a survey might be better run on unload as then the person would have visited your site already and might be better able to answer questions.

You should also provide the user with an easy way to close the window. Sure they can just click the X in the top right corner but providing a larger button in the window itself shows consideration for the browsing experience of your visitors.

Implementation

So you know how popups can help, you know how to make them less annoying, but how do you actually implement all of this? Well, you use Javascript as outlined below.

First you need to use a couple of standard Javascript functions that will allow you to set and read cookies. The below functions are pretty standard and so I will not go over how they work or what they're doing, you don't need to know that to implement this anyways.

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) 
		break; 
	}
	return null;
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}