Article

Home » Client-side Coding » JavaScript & Ajax Tutorials » Use a Friendly Popup to Boost eZine Subscriptions

About the Author

Mitchell Harper

author_mitchellharper Mitchell is the lead developer for Interspire, who develop re-brandable Internet software and tools to help Web developers increase their customer base and make more revenue. Mitchell can be reached via email at mitchell@interspire.com.

View all articles by Mitchell Harper...

Use a Friendly Popup to Boost eZine Subscriptions

By Mitchell Harper

January 25th, 2002

Reader Rating: 8.5

Page: 1 2 Next

Every top Internet marketer knows that ezine advertising and promotions are some of the best ways to drive targeted traffic to your site for little to no cost. If you run a Website and send an ezine to your visitors, how do you let them signup to receive it? Do they have to navigate through 5 pages on your site just to get to the signup page, or do you let them have it as soon as they enter your site?

If they can't see the signup form to join your ezine as soon as they come to your site, then chances are that you're missing out on grabbing their email address all together. Using some simple HTML and a bit of JavaScript, you can easily get your signup form to where it needs to be, without ruining your visitors' experience on your site.

A Popup is the Answer

The technique I'm about to describe is one of the best I've ever used to attract more subscribers to my ezine. Firstly, it involves the creation of a popup window using JavaScript. Like many other Webmasters, I once thought that using a popup window degraded the professionalism of my site. Boy was I wrong!

Adding a simple signup popup to my site increased my ezine subscriptions from about 20 a day to well over 100! No joke.

Visitors don't want to be annoyed by popup windows every time they visit your site, however. This is where cookies come into play. Using cookies, you can make their browser "remember" if your ezine signup page has already been displayed. If it has, then the page won't be displayed again.

Getting and Setting the Cookie

To start with, we need to create the generic functions that will actually get and set the cookies from the user's browser. To access the visitor's cookies through JavaScript, we manipulate the document.cookie value. It contains all the cookies that have been set for this user when they visit our site. It's important to note that we can only access the cookies that we have set, and not those set by other sites.

Cookies are stored by the Web browser in a plain text file on the visitor's computer. The browser checks the cookie file on their hard drive to see whether it contains any cookies for our site; if it does, the browser loads them automatically for us.

Each cookie is stored as a name/value pair. A sample document.cookie variable looks like this:

myCookie=myValue;myName=Mitchell;mySite=www.devarticles.com;

We will create two functions named setCookie and getCookie. They're created between <script> and </script> tags, just before the </head> tag of our HTML page, like this:

<script language= "JavaScript">

function setCookie(cookieName, cookieValue, cookiePath,  
cookieExpires)  
{

cookieValue = escape(cookieValue);  
if (cookieExpires == "")  
{  
var nowDate = new Date();  
nowDate.setMonth(nowDate.getMonth() + 6);  
cookieExpires = nowDate.toGMTString();  
}  

if (cookiePath != "")  
{  
cookiePath = ";Path=" + cookiePath;  
}  

document.cookie = cookieName + "=" + cookieValue +  
";expires=" + cookieExpires + cookiePath;
}

function getCookie(name)  
{
var cookieString = document.cookie;  
var index = cookieString.indexOf(name + "=");  

if (index == -1)
{
return null;  
}

index = cookieString.indexOf("=", index) + 1;  
var endstr = cookieString.indexOf(";", index);  

if (endstr == -1)
{
endstr = cookieString.length;  
}

return unescape(cookieString.substring(index, endstr));
}
</script>

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links