Hi, Experts!
I wrote a small piece of js code. It is supposed to do the following:
On exit, it detects a cookie "nopop" first. If found the cookie, do nothing. If not, popup a new window and set the "nopop" cookie.
My problem seems random.
1) If I see the "nopop" cookie in my
C:\Documents and Settings\...\Cookies
subdir, then I can not get the cookie by calling getCookie().
2) If I do NOT see the "nopop" cookie in my
C:\Documents and Settings\...\Cookies
subdir, then I CAN get the cookie by calling getCookie().
How strange it is!!
The following is my code:
You may need make your own invite.html for your test.
Thank you so much for you help.
I wrote a small piece of js code. It is supposed to do the following:
On exit, it detects a cookie "nopop" first. If found the cookie, do nothing. If not, popup a new window and set the "nopop" cookie.
My problem seems random.
1) If I see the "nopop" cookie in my
C:\Documents and Settings\...\Cookies
subdir, then I can not get the cookie by calling getCookie().
2) If I do NOT see the "nopop" cookie in my
C:\Documents and Settings\...\Cookies
subdir, then I CAN get the cookie by calling getCookie().
How strange it is!!
The following is my code:
Code:
<HTML>
<HEAD>
<TITLE>cookie test</TITLE>
<script language=JavaScript>
function closeit()
{
window.open('javascript:window.close()','newwin');
}
function openit(sURL, name)
{
var name1 = "nopop";
var value = "0123456789";
var expireDate = new Date();
expireDate.setTime(expireDate.getTime() + (24*60*60*1000));
if(!getCookie(name1) )
{
newwindow=window.open(sURL,"newwin","width=300, height=300");
setCookie(name1,value,expireDate,"/",null,true);
}
}
function setCookie(name1,value,expires,path,domain,secure)
{
document.cookie = name1 + "=" +escape(value) +
((expires) ? ";expires=" + expires.toGMTString() : "") +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}
function getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
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;
}
</script>
</HEAD>
<body bgcolor="#ffffff" onUnload="javascript:openit('/pops/invite.html', 'id')" onload="javascript:closeit()">
<script language="javascript">
var cookieVal = getCookie("nopop");
document.write ("<h3>cyan cookieVal = #" + cookieVal + "#</h3>");
</script>
</body>
</html>
You may need make your own invite.html for your test.
Thank you so much for you help.