www.webdeveloper.com
Results 1 to 2 of 2

Thread: how to set cookies on browser through javascript

  1. #1
    Join Date
    Oct 2012
    Posts
    9

    how to set cookies on browser through javascript

    when I surf http://www.youtube.com/html5/?gl=FR&hl=fr
    and click "join youtube html5"
    I will notice that the visit creates a cookie on my firefox browser

    the information is as follows, where "f1=40000000&f2=40000000" is the key

    I want to create a blank html page which has javascript codes
    when I visit this html page, I hope it will set the same cookies for me
    I mean the domain is "youtube.com" and the content is f1=40000000&f2=40000000
    expiry time is not important, as long as it can be maintained before the browser is closed
    the reason for me to do this is at the end if you want to know
    how to write the code? thanks

    Code:
    Host:                 .youtube.com
    Name:                 PREF
    Path:                 /
    Content:              f1=40000000&f2=40000000
    Content raw:          f1=40000000&f2=40000000
    Expires:              At end of session
    Expires raw:          0
    Send for:             Encrypted connections only
    Send for raw:         true
    Created:              Mon 08 Oct 2012 01:10:42 PM UTC
    Created raw:          1349701841568107
    Last accessed:        Mon 08 Oct 2012 01:10:46 PM UTC
    Last accessed raw:    1349701846292406
    HTTP only:            No
    HTTP only raw:        false
    This domain only:     Yes
    This domain only raw: true
    Policy:               no information available
    Policy raw:           0
    Status:               no information available
    Status raw:           0

    reason for doing this: the modified firefox will delete all cookies when it is closed, and I want to do some repeated test by scripts, so I want to use script to make this firefox to visit the created blank html page to get the cookie

  2. #2
    Join Date
    Oct 2012
    Posts
    9
    I make a html file called test.html, and then I use firefox to open it, but I can't find any cookies related to my script on firefox, what is wrong with my html and javascript code?

    Code:
    <html>
      <head>
        <title>
          JavaScript Example 1 -- Hello World
        </title>
    <script type="text/javascript">
    <!--
    function writeCookie() 
    {
     var content="f1=40000000&f2=40000000";
     var domain = "youtube.com";
     var name = "PREF";
     var path = "/";
     var the_cookie  = "name="+name+";content="+content+";domain="+domain+";path="+path+";expires=0;";
     document.cookie = the_cookie;
    }
    writeCookie();
    alert(document.cookie);
    //-->
    </script>  
    </head>
      <body>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles