Home arrow JavaScript arrow Page 3 - Boosting Ezine Subscribers With a Popup Window
JAVASCRIPT

Boosting Ezine Subscribers With a Popup Window


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. In this article Mitchell shows us how to use JavaScript to create a popup window that allows visitors to our web sites to enter their email address and receive our newsletter.

Author Info:
By: Mitchell Harper
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
April 17, 2002
TABLE OF CONTENTS:
  1. · Boosting Ezine Subscribers With a Popup Window
  2. · A Popup is the Answer
  3. · How setCookie Is Used
  4. · Conclusion

print this article
SEARCH DEVARTICLES

Boosting Ezine Subscribers With a Popup Window - How setCookie Is Used
(Page 3 of 4 )

The setCookie function shown above accepts the name, value, path and expiry date of a cookie to set. It's used like this:

setCookie('myCookie', 'myValue', '', '');

This would set a cookie named "myCookie", which would contain the value "myValue". The last two arguments to the setCookie function are the cookie path and its expiry date. As you can see, you can leave the last two arguments as ''. The setCookie function will use default values if they are empty.

The getCookie function accepts the name of a cookie to retrieve, and returns its value if it exists:

var c = getCookie('myCookie');

"c" would now contain "myValue".

Displaying the Ezine Signup Window
Now that we can get and set cookies, we're ready to actually use the setCookie and getCookie functions. We will create a function that will check whether or not a specific cookie is set. If it is, then we will not display the ezine popup window. On the other hand, if there is no cookie set, we will display the ezine popup page and set a cookie to indicate that the signup form has been shown. The function is very simple, and looks like this:

function doPopup()
{
var ezine = getCookie('popupShown');
setCookie('popupShown', 'true', '', '');

if(ezine == '')
{ // Show the popup window
window.open('ezine.html', 'ezineWin', 'width=500,height=400');
}
}


The doPopup function starts by creating a new variable named ezine, which will contain the value of the "popupShown" cookie. Irrespective of whether or not the getCookie() function returns a value, we set the "popupShown" cookie. Our "setCookie" function automatically sets a period of time for which the cookie will persist. As you can see from the code snippet below (taken from the setCookie function we created above), the default is 6 months:

var nowDate = new Date();
nowDate.setMonth(nowDate.getMonth() + 6);
cookieExpires = nowDate.toGMTString();


By resetting the "popupShown" cookie each time the user visits this page, we're making sure the popup is never displayed again as long as they continue to visit the site at least once every six months.

The most popular times to display the actual signup form are when the user jumps to another page or exits your site. Both of these events trigger the onUnload event handler. We need to tell the browser to call the doPopup function when this occurs so we modify the <body> tag like this:

<body onUnload="doPopup()">

Now, if the visitor jumps to another page on our site, or closes the browser window, then our ezine popup will be displayed in a new window.
blog comments powered by Disqus
JAVASCRIPT ARTICLES

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials