Advanced Search

Results 1 to 8 of 8

Thread: Cookie Setting

  1. #1
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    270
    Thanks
    3
    Thanked 17 Times in 17 Posts

    Default Cookie Setting

    I have been trying to set a cookie and use an alert to check to see if the cookie was actually set; however, it seems like it is failing to set the cookie:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Game Selection</title>
    <style>
    * { margin:0 auto; padding:0;}
    body { background-color:#CCCCCC;}
    
    #play { width:200px; border:1px solid black; text-align:center; margin-top:5px; cursor:pointer; background:white;}
    #play:hover { text-decoration:underline;}
    
    #bce_popup {
    	position:absolute;
    	top:0;
    	left:0;
    	background-color:black;
    	background-color: rgba(0,0,0,0.85);
    	width:100%;
    	height:100%;
    	display:none;
    }
    
    #bce_main {
    	top:10px;
    	height: 80%;
    	width:80%;
    	margin-top:10px;
    	clear:both;
    	position:absolute;
    	display:none;
    	background-color:transparent;
    	border:1px solid black;
    	background-color:white;
    	margin-left:10%;
    }
    </style>
    
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script type="text/javascript">
    $(document).on('click','#play',function(){
    	document.cookie=escape("username=xxx xxx; expires=Thu, 18 Dec 2014 12:00:00 GMT; path=/")
    	alert(document.cookie);
    	})
    	
    </script>
    </head>
    <body>
    
    <div id="play">Display</div>
    
    </body>
    </html>
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,621
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    You're escaping the entire string (including all the settings). You should only be escaping the value part:
    Code:
    document.cookie="username="+escape("xxx xxx")+";expires=Thu, 18 Dec 2014 12:00:00 GMT;path=/";
    alert(document.cookie);  // alerts "username=xxx%20xxx"
    Using your original code, however, the cookie was set (the alert showed its name was the entire encoded string, and it had no value). Did you get different results?
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  3. #3
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    270
    Thanks
    3
    Thanked 17 Times in 17 Posts

    Default

    This is weird. Nothing is appearing for me. It says javascript alert but in the message part it is blank? Also, yours is the same way. I tried it on Chrome and Opera
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,621
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Dunno.

    To be clear, I'm testing only the document.cookie part; I haven't included the onclick or any of the markup.
    Does this demo work for you?
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  5. #5
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    270
    Thanks
    3
    Thanked 17 Times in 17 Posts

    Default

    Yes that works, do cookies not work if they are local?
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,621
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Are you using a local server (e.g., http://localhost), or just opening the file from your desktop?
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  7. #7
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    270
    Thanks
    3
    Thanked 17 Times in 17 Posts

    Default

    Just opening the file like a normal HTML. Do i need to use my localhost with XAMPP?
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  8. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,621
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Well, I wouldn't have thought so, but after testing on Chrome it appears you might: I get a blank cookie that way too. You have xampp installed? give it a try.
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

Similar Threads

  1. Cookie setting on splash page
    By BarryDeez in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 11-14-2010, 03:30 PM
  2. Setting A Certain Delay
    By gabrola in forum JavaScript
    Replies: 11
    Last Post: 10-27-2008, 10:43 PM
  3. Changing from session cookie to permanent cookie
    By boisemedia in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 03-21-2008, 10:07 PM
  4. Replies: 4
    Last Post: 12-04-2007, 09:52 PM
  5. Setting BG Color with a cookie function
    By CarolinaN in forum JavaScript
    Replies: 1
    Last Post: 06-11-2005, 02:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •