Have a Javascript that keeps a cookie on a popup

C

Connie Walsh

Hi:

I gleaned a javascript off of the web:

http://www.hypergurl.com/popup.html

that sets a cookie everytime someone visits your site. If it is the
first visit in x number of days then a popup will appear. It would be
great for my application but I can't get it to work. Here is my code:

http://www.software-in-a-box.com/shop/skin_default/template.html

Here is where my site is displayed (and the popup should show up):

http://www.software-in-a-box.com/shop

Here is a snippet of my code. I tried putting open.window's in my code
in the checkcount and getcookie functions and no window was opened. Is
there an easier thing to debug with. I use safari and I hear it has no
debugger...sux. I have no idea what was going on. I tried netscape still
no windows.

Thanks for any help you can provide.

Connie



<html>
<head>
<title>Software-In-A-Box.com</title>
<meta description="A computer software company that sells computer games
and other computer software to
consumers">
<meta keywords="computer software, computer games, computer stuff>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<script LANGUAGE="Javascript">
<!-- Hide javascript from older browsers --
function PopUp(theURL,winName,features)
{window.open(theURL,winName,features);}
// end hide -->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
..txt1 {
font: 10px Tahoma;
color: #5A5A5A;
}
..txt2 {
font: 11px Tahoma;
color: #5A5A5A;
}
..txt3 {
font: 11px Tahoma;
color: #5A5A5A;
}
body,td,th {
font-size: 10px;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->


<!-- Begin
var expDays = 2; / number of days the cookie should last
var page =
"http://www.software-in-a-box.com/shop/skin_default/popup.html"; /URL to
the pop-up
var windowprops = ""; / variables
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 = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);

window.open(page, "", windowprops);

}
else {
count++;
SetCookie('count', count, exp);
}
}
/ End -->


</script>
</head>

<body style="padding:0;margin:0 " onLoad="checkCount()" >
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
 
C

Connie Walsh

Well after some digging I found jslint. A javascript verifier.
Apparently there were a lot of problems with the code. I have posted the
working copy here: (take out the extra Hello world lines)

Connie


<html>
<head>

<script LANGUAGE="JavaScript" >

var expDays = 1;
var page = "Users/walshclan/Desktop/6384/html/popup.html";
var windowprops =
"width=200,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
alert("hello world");
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 ) {break; }
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((!expires) ? "" : ("; expires=" + expires.toGMTString())) +
((!path) ? "" : ("; path=" + path)) +
((!domain) ? "" : ("; domain=" + domain)) +
((secure) ? "; secure" : "");
}
function DeleteCookie (name) {

var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
alert("hello world");
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
var count = GetCookie('count');
alert("hello world");
if(!count) {
SetCookie('count','1');
return 1;
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('count');
SetCookie('count',newcount,exp);
return count;
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
{endstr = document.cookie.length;}
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
var count = GetCookie('count');
alert("hello world");
if (!count) {
count=1;
SetCookie('count', count, exp);

window.open(page, "", windowprops);

}
else {
count++;
SetCookie('count', count, exp);
}
}



function test () {
alert("hello world");
}


</script>
</head>
<body onload="checkCount()">
</body>
</html>
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Wed, 22 Sep 2004
02:15:20, seen in Connie Walsh
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);

Is var exp = new Date(0) not better ?????
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
alert("hello world");
}

var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));


exp.setDate(exp.getDate() + expDays) // is better; less so if all
// users live in places like
// Hawaii or Uganda



<FAQENTRY>

The FAQ index has nothing general on cookies. Sec 4.4 should be
generalised :


4.4 Why and how are cookies used ?

Cookies are used to maintain information either during ... or for a
longer definable period. Users often do not allow them.

To test whether the present browser accepts cookies, write
a cookie, read it back and check whether it is the same.

For example cookie code, see ...

http://tech.irt.org/articles/js064/index.htm
Additional Notes:
http://www.jibbering.com/faq/faq_notes/cookies.html



if != whether
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top