No-Kill Pop Box; Part III
This article provides the means to use cookies so your No-Kill Pop Box is displayed only once to a visitor for a pre-determined number of days.
Please see the other two articles in this series, linked from web development article index.
-
"No-Kill Pop Box (Instead of Popups)"
The basic code for creating a Pop Box.
-
"No-Kill Pop Box; Part II"
Comparisons with focus on differences of the No-Kill Pop Box and Pop-ups/unders. Code for delayed opening of the No-Kill Pop Box and to open and close the No-Kill Pop Box with links.
The demo page at contains the complete code necessary to implement the No-Kill Pop Box with cookies.
If you haven't read the other two articles in this series, I urge you to do so now. Unless you are a proficient JavaScript programmer, the rest of this article may make little sense until familiarity with the other two articles is attained.
The global variable and functions that were added since the second of this article series are:
-
A global variable named DaysToLive
Here, specify the number of days you want the cookie to live, a maximum of 3652 days, representing 10 years. If you want the cookie to disappear when the browser is closed (called "session cookies"), specify 0 (zero) days.
-
Function SetCookie()
This is the function that sets the cookie when the No-Kill Pop Box is displayed.
-
Function GetCookie()
This function is used to determine whether or not the cookie exists in the browser.
-
Function OpenPopBoxIfOkay()
This function is called when a page first loads. It uses function GetCookie() to determine whether or not the No-Kill Pop Box should be displayed.
Function OpenPopBoxIfOkay() must be called or the No-Kill Pop Box won't ever be displayed and no cookie will be set. The function can be called using any of the following methods:
-
In the BODY tag itself with
onLoad="OpenPopBoxIfOkay()"
Example:
<BODY onLoad="OpenPopBoxIfOkay()">
The above calls the function as soon as the page completes loading.
-
Somewhere in the BODY area with
<script type="text/javascript" language="JavaScript"><!--
OpenPopBoxIfOkay();
//--></script>
The above calls the function when the browser loads the code.
-
Somewhere in the BODY area with
<script type="text/javascript" language="JavaScript"><!--
setTimeout('OpenPopBoxIfOkay()',3000);
//--></script>
The above calls the function 3 seconds after the browser loads the code. The number 3000 in the above codes represents 3000 milliseconds delay. Adjust that number as appropriate for your installation.
You'll notice that the demonstration for this article contains a WillMaster Possibilities subscription form.
When a form is put into the No-Kill Pop Box and the form submitted, the "thank you" page will be a new page, like it would be if the form was submitted from a normal page -- the "thank you" page will not display inside the No-Kill Pop Box.
Because the No-Kill Pop Box is displayed only the one time, the "thank you" page can be the same page the form was submitted from. When the "thank you" page loads, the No-Kill Pop Box won't display because it has already been displayed once. In effect, the form user is sent to the same page the form was submitted from -- except the page no longer displays the form.
Note: Browsers with cookies disabled, will show the form every time the page loads. (I've never done a survey to determine how many cookies-disabled browsers visit our sites. I'm thinking the number is low, but I can't be certain.)
The first three parts of this series have provided the code necessary to use No-Kill Pop Boxes in a professional manner.
Question:
Did you find this article interesting and understandable? How can it be improved?
Your response is anonymous.
When done typing, click anywhere outside the box. [more info]
Will Bontrager
©2003 Bontrager Connection, LLC
Please note:
Articles on this website are presented "as is". However -
If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Ask one of our Experts and you'll have your answer!
Click here for details.