469,361 Members | 2,264 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,361 developers. It's quick & easy.

Cookies don't survive browser close...

Hi,

I'm trying to use jquery to do some things. It works well, but I can't seem to get it to set a cookie that doesn't expire when I end the browser session.

The books and examples say this should work:

Expand|Select|Wrap|Line Numbers
  1.         function CheckPW(){
  2.  
  3.  
  4.             var PWDiv = document.getElementById("PWDiv");
  5.             var Uname = document.getElementById("UserName");
  6.             var Pword = document.getElementById("PassWord");
  7.  
  8.             var MyUser=Uname.value;
  9.             var MyUN=Uname.value;
  10.             var MyPW=Pword.value;
  11.             for (var x in User) {
  12.                 //PWDiv.innerHTML += x + " " + User[x] + "<br>";
  13.                 if(MyUN == x) {
  14.                     if(MyPW == User[x]){
  15.  
  16.                         PWDiv.innerHTML += " Logged In as " + x + "<br>";
  17.                         $.cookies.set("PWCookie", x, {expires: 15});
  18.  
  19.                     }
  20.                 } else {
  21.                     //PWDiv.innerHTML += "Oh, well... <br>";
  22.                 }
  23.  
  24.             }
  25.         }
  26.  
  27.             function LogInit(){
  28.                 logcookie = $.cookies.get("PWCookie");
  29.                 var Uname = document.getElementById("UserName");
  30.                 //alert(logcookie);
  31.                 Uname.value = logcookie;
  32.  
  33.                             }
  34.  
Firefox(v3.6.3), IE8, and Google Chrome all reload the cookie as long as I have not closed the session.

When I close the browser, the cookie disappears.

One other thing... the web page and scripts are contained in a folder on my local machine. Do these have to be on a server (a bona fide web server) to work?

Any Thoughts???

Sincerely,

Ken
Apr 26 '10 #1
3 1589
acoder
16,027 Expert Mod 8TB
How are you accessing the page? Using localhost or 127.0.0.1 or similar or via file:// ?
Apr 29 '10 #2
I'm accessing on my development machine by double clicking the html... so I suppose it is by *file:// -- but it does the same when I put the files on my website, and also when I have a friend try it from his computer.

Ken
Apr 29 '10 #3
In Fact...

http://www.elvehjem.com/MissMap/MissMap.html is the site,

and you can try these 2 U/N / P/W combinations, if you would be so kind!

"Red Rider" : "Trigger",
"Easy Rider" : "Harley"

Thanks!

Ken
Apr 29 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

20 posts views Thread by Brian Burgess | last post: by
5 posts views Thread by anony | last post: by
1 post views Thread by Joe Fallon | last post: by
3 posts views Thread by Raghu Raman | last post: by
7 posts views Thread by Marcus | last post: by
3 posts views Thread by Phillip N Rounds | last post: by
3 posts views Thread by johnny | last post: by
4 posts views Thread by surf_doggie | last post: by
3 posts views Thread by Matthew Laping | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.