spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

Developer News
Metasploit 3.2 Offers More 'Evil Deeds'
'Thank You Apple. Seriously.'
The Buzz: BlackBerry App Store Seen Next
JavaScript Tip of the Week for November 25, 1996: Source Code: Everything You Ever Wanted to Know About Cookies

What Cookies Are and How to Use Them
Storing Cookies In Arrays
Welcome New Visitors with A Special Page



This code is put in the HTML document where you want to utilitize Cookies:
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
/* This code is Copyright (c) 1996 Nick Heinle and Athenia Associates, 
 * all rights reserved. In order to receive the right to license this 
 * code for use on your site the original code must be copied from the
 * Web site webreference.com/javascript/. License is granted to user to 
 * reuse this code on their own Web site if and only if this entire copyright
 * notice is included. Code written by Nick Heinle of webreference.com.
 */

function getCookie (name) {
var dcookie = document.cookie; 
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
        while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
                if (dcookie.substring(cbegin, vbegin) == cname) { 
                var vend = dcookie.indexOf (";", vbegin);
                        if (vend == -1) vend = clen;
                return unescape(dcookie.substring(vbegin, vend));
                }
        cbegin = dcookie.indexOf(" ", cbegin) + 1;
                if (cbegin == 0) break;
        }
return null;
}

function setCookie (name, value, expires) {
        if (!expires) expires = new Date();
document.cookie = name + "=" + escape (value) + 
"; expires=" + expires.toGMTString() +  "; path=/";
}

function delCookie (name) {
var expireNow = new Date();
document.cookie = name + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}
// -->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
This code is put in the HTML document where you want to utilitize Cookies stored in Arrays:
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--

/* This code is Copyright (c) 1996 Nick Heinle and Athenia Associates, 
 * all rights reserved. In order to receive the right to license this 
 * code for use on your site the original code must be copied from the
 * Web site webreference.com/javascript/. License is granted to user to 
 * reuse this code on their own Web site if and only if this entire copyright
 * notice is included. Code written by Nick Heinle of webreference.com.
 */

function getCookie (name) {
var dcookie = document.cookie; 
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
        while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
                if (dcookie.substring(cbegin, vbegin) == cname) { 
                var vend = dcookie.indexOf (";", vbegin);
                        if (vend == -1) vend = clen;
                return unescape(dcookie.substring(vbegin, vend));
                }
        cbegin = dcookie.indexOf(" ", cbegin) + 1;
                if (cbegin == 0) break;
        }
return null;
}

function setCookie (name, value, expires) {
        if (!expires) expires = new Date();
document.cookie = name + "=" + escape (value) + 
"; expires=" + expires.toGMTString() +  "; path=/";
}

function delCookie (name) {
var expireNow = new Date();
document.cookie = name + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

function setCookieArray(name){
this.length = setCookieArray.arguments.length - 1;
        for (var i = 0; i < this.length; i++) {
        this[i + 1] = setCookieArray.arguments[i + 1]
        setCookie (name + i, this[i + 1], expdate);
        }        
}

function getCookieArray(name){
var i = 0;
        while (getCookie(name + i) != null) {
        this[i + 1] = getCookie(name + i);
        i++; this.length = i; 
        }
}

var expdate = new Date();
expdate.setTime (expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 

var testArray = new setCookieArray("_jtotw", "my", "data", "is", "very", "important");

var testArray = new getCookieArray("_jtotw");
// -->
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
document.write ( testArray[1] + " " );
document.write ( testArray[2] + " " );
document.write ( testArray[3] + " " );
document.write ( testArray[4] + " " );
document.write ( testArray[5] + " " );
</SCRIPT>
</BODY>
</HTML>
This code is put in the HTML document where you want to utilitize the Welcome page (most likely one of your main pages, where new visitors would start out):
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
/* This code is Copyright (c) 1996 Nick Heinle and Athenia Associates, 
 * all rights reserved. In order to receive the right to license this 
 * code for use on your site the original code must be copied from the
 * Web site webreference.com/javascript/. License is granted to user to 
 * reuse this code on their own Web site if and only if this entire copyright
 * notice is included. Code written by Nick Heinle of webreference.com.
 */

function getCookie (name) {
var dcookie = document.cookie; 
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
        while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
                if (dcookie.substring(cbegin, vbegin) == cname) { 
                var vend = dcookie.indexOf (";", vbegin);
                        if (vend == -1) vend = clen;
                return unescape(dcookie.substring(vbegin, vend));
                }
        cbegin = dcookie.indexOf(" ", cbegin) + 1;
                if (cbegin == 0) break;
        }
return null;
}

function setCookie (name, value, expires) {
        if (!expires) expires = new Date();
document.cookie = name + "=" + escape (value) + 
"; expires=" + expires.toGMTString() +  "; path=/";
}

function delCookie (name) {
var expireNow = new Date();
document.cookie = name + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

function toggleWelcome() {
        if (getCookie(cookieName) == "true") setCookie(cookieName, "false", top.expdate);
        else setCookie(cookieName, "true", top.expdate);
}

function offTemp() {
        if (getCookie(cookieName) == "true") {
        setCookie(cookieName, "offtemp", expdate);
        history.go(0);
        }
}

var expdate = new Date();
expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
var cookieName = "_welcomeJTotW";
var welcomePage = "part03_welcome.html";

        if (getCookie(cookieName) == null || getCookie(cookieName) == "true") {
        setCookie(cookieName, "true", expdate);
        document.write ('lt;FRAMESET ROWS = "100%, *" FRAMEBORDER = NO BORDER = 0gt;');
        document.write ('lt;FRAME SCROLLING = AUTO SRC = "' + welcomePage + '"');
        document.write ('MARGINWIDTH = 5 MARGINHEIGHT = 5gt;');
        document.write ('lt;/FRAMESETgt;');        
        }
        else if (getCookie(cookieName) == "offtemp") {
        setCookie(cookieName, "true", expdate);
        }
// -->
</SCRIPT>
</HEAD>
<BODY>

This is the normal Page.

</BODY>
</HTML>
Then put this small form, which turns the welcome screen off, in the "welcome" HTML document:
<FORM>
<INPUT TYPE = "checkbox" onClick = "top.toggleWelcome()">
Don't show this welcome screen again.
</FORM>
You can also include this small link, which brings the user to the normal page by temporarily disabling the welcome cookie:
<A HREF = "javascript:top.offTemp()">Enter Main Page</A>



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview · Controllers: Programming Application Logic - Part 2 · How to Use JavaScript to Validate Form Data
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Choosing the Right Online Backup Provider · Mother Avaya Nurtures Her Technology Partners · Software as a Service a Winning Model for Hotspot Provider