xbl1 Posted November 3, 2007 Share Posted November 3, 2007 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 More sharing options...
Jesdisciple Posted November 3, 2007 Share Posted November 3, 2007 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 More sharing options...
Reg Edit Posted November 3, 2007 Share Posted November 3, 2007 document.cookie="bNumber=" +escape("1_2_3")+ ";expires="+exdate.toGMTString());There's an extra ) on the end of that line. It will cause a javascript error, so the cookie won't get set. Link to comment Share on other sites More sharing options...
xbl1 Posted November 3, 2007 Author Share Posted November 3, 2007 You are right, the problem from the letter extra ).Thanks a lot. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.