| |

VerySource

 Forgot password?
 Register
Search
View: 1203|Reply: 4

Ask a question about cookie reading

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-23 23:00:01
| Show all posts |Read mode
I wrote this in asp:
Response.Cookies ("cookie1") ("mm3") = "nickname"

So how to read ("cookie1") ("mm3") cookie value in javascript?


Asked here, I forgot to inform you.
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-3 23:30:01
| Show all posts
<script language="javascript">
      var strCookie=unescape(document.cookie);
      var strTT="cookie1=mm3=";
      if(strCookie.indexOf(strTT)>=0)
      {
            var strT1=strCookie.substring(strCookie.indexOf(strTT) + strTT.length)
            var strT2=strT1.substring(0,strT1.indexOf(";"))
            alert(strT2);
      }

</script>
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 United States

 Author| Post time: 2020-7-4 18:00:01
| Show all posts
But when there are multiple arrays, you can't read them. . .
eg:
Response.Cookies("cookie1")("mm3")= "nickname"
Response.Cookies("cookie1")("mm2")= "nicknamexxxx"

The above method will not work.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-8 10:15:01
| Show all posts
Cookie is a string for javascript, cut it yourself~
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-11 02:15:01
| Show all posts
var strCookie=new String();
      strCookie=unescape(document.cookie);
      strTT="cookie1="
      if(strCookie.indexOf(strTT)>=0)
      {
      
            var strT1=new String();
            var strS=new String();
            var arrStr=new Array()
            strT1=strCookie.substring(strCookie.indexOf(strTT) + strTT.length)
            arrStr=strT1.split("&");
            for(var i=0;i<arrStr.length;i++)
            {
               strS=arrStr[i];
               switch(strS.substring(0,strS.indexOf("=")))
               {
                 case "mm1": alert("Username===" + strS.substring(strS.indexOf("=")));break
                 case "mm2": alert("The nickname is ===" + strS.substring(strS.indexOf("=")));break
                 case "mm3": alert("Pen name is ===" + strS.substring(strS.indexOf("=")));break
               }
            }
      }
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list