a question about to set many cookie with jscript RRS feed

  • Question

  • I have writed code like the following.

    <script type="text/javascript">
    document.cookie = "name1=11; name2=13; path=/;";

    but only name1=11...I can't find name2=13,why?what is error.

    Friday, February 3, 2012 6:10 PM

All replies

  • If you want to set multiple cookie try the following code

    <script type="text/javascript">
        document.cookie = "name1=11; path=/;";
        document.cookie = "name2=13; path=/;";

    document.cookie will accept the following parameters

    name       Name of the cookie
    value      Value of the cookie
    [expires]  Expiration date of the cookie (default: end of current session)
    [path]     Path where the cookie is valid (default: path of calling document)
    [domain]   Domain where the cookie is valid (default: domain of calling document)
    [secure]   Boolean value indicating if the cookie transmission requires a secure transmission

    All the above parameters has to ";" splitted, so if you want to set multiple cookies you have to use document.cookie multiple times.

    Tuesday, February 7, 2012 9:18 AM