Jump to content



Recommended Posts

Hi,i am trying to create a cookie in a page, and use the cookie value in another page, but it does not work, could anyone tell me why?page A

<html><body><script type="text/javascript">var exdate=new Date();exdate.setDate(exdate.getDate()+1);document.cookie="bNumber=" +escape("1_2_3")+ ";expires="+exdate.toGMTString());</script></body></html>

Page B

<html><body><script type="text/javascript">bNumber="bNumber";  c_start=document.cookie.indexOf("bNumber=")  if (c_start!=-1)	{ 	c_start=c_start + bNumber.length+1 	c_end=document.cookie.indexOf(";",c_start)	if (c_end==-1) c_end=document.cookie.length	 bNumber=unescape(document.cookie.substring(c_start,c_end))	 alert(" the string are " + bNumber);	} </script></body></html>

Link to comment
Share on other sites

Here's your problem:

document.cookie="bNumber=" +escape("1_2_3")+ ";expires="+exdate.toGMTString());
Remove the last parenthesis and it works fine. (It's always the little things that hang a script up, isn't it?)For your future reference, it was Firefox's error console that told me that.EDIT: It looks like Reg Edit posted about the same time I edited my post to say the above. :\
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...