Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Cookie in JavaScript

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you the example analysis of Cookie in JavaScript, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The read operation of cookie in Cookie1.js function getCookie (c_name) {if ([xss_clean] .length > 0) {/ / first query whether cookie is empty, if so, return "" clocked start = [XSS _ clean] .indexOf (c_name + "=") / check whether the cookie exists through the indexOf () of the String object. If it doesn't exist, it's-1 if. {c_start=c_start + c_name.length+1 / / the last + 1 actually means the "=" sign, so you get the starting position of the cookie value: [XSS _ clean] .indexOf (" ", c_start) / / in fact, I was a little dizzy when I saw the second parameter of indexOf (), and then I remembered that it indicated the specified location to start the index. This sentence is to get the end position of the value. Because you need to consider whether it is the last item, you can determine whether or not the ";" sign exists to determine if (c_end==-1) cendend = [XSS _ clean] .length return unescape ([xss_clean] .substring (centering start and cending end)) / / the value is obtained through substring (). If you want to understand unescape (), you have to know what escape () does, which is a very important foundation. If you want to know, you can search for it and explain the details of cookie coding}} return "} 2.cookie simple storage operation $.cookie (" groupCode ", 222) 3.cookie set expiration time [xss_clean] =" name=value "at the end of the article. Expires=date "4.cookie modification [xss_clean] =" username=zhangsan "; [xss_clean] =" username=lisi "; var cookies = [xss_clean]; console.log (cookies); 5.cookie deletion [xss_clean] =" username=zhangsan "; [xss_clean] =" username=; expires=Thu, 01 Jan 1970 00:00:00 GMT "; var cookies = [xss_clean]; console.log (cookies); above is all the content of the article" sample Analysis of Cookie in JavaScript ". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report