View Single Post
  #3 (permalink)  
Old 03-21-2005, 12:17 AM
doucetted doucetted is offline
Registered User
 
Join Date: Mar 2005
Posts: 4
OK I have figured out how to set a cookie with the value of copyright to expire when the browser closes, I put this code in the firs page and it seems to work fine...

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
createCookie('www.mysite.com','copyright',0)
function createCookie(name,value,days)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
var ck = name+"="+value+expires+"; path=/";
document.cookie = ck;
}

// -->
</script>


Now here is the tricky part, I put the following code in the second page (index2.html)...

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
go_to = "http://www.mysite.com/index.html";

function readCookie('www.mysite.com')
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
window.location = go_to;
}
// -->
</script>


What I want to do is if the cookie doesn't exist or is null then go to index.html otherwise just continue loading this web page. This is not working.

Any help.
Reply With Quote