Dépendra de la définition de Wikipédia : Cookie la sécurité des données purposes navigateur. cookie et comment l'utiliser, cet article sans JavaScript peut-être mieux.
- Demo
- Agrandir
- Recharger
- New window
G�n�rez vos vid�os d'entreprise par l'IA avec la voix ou simplement du texte
Votre premi�re application vid�o AI GRATUITE ! Automatisez votre premi�re vid�o AI. Cr�ez votre vid�o professionnelle en 5 minutes gr�ce � l'IA. Aucun �quipement ni comp�tence en montage vid�o requis. Production vid�o sans effort pour les sp�cialistes du marketing de contenu.
This is my very first weekly tips for web design and development. From now on, I'll be posting it every week, and will cover all sort of interesting, helpful web design and development tips and tricks.
"In computing, a cookie (also tracking cookie, browser cookie, and HTTP cookie) is a small piece of text stored on a user's computer by a web browser. A cookie consists of one or more name-value pairs containing bits of information such as user preferences, shopping cart contents, the identifier for a server-based session, or other data used by websites." - Wikipedia - HTTP Cookie
Relates:
- Cookies in JavaScript
- JavaScript Delicious Cookies
- JavaScript Cookie Enabled script
Yes, we'll look into how to manipulate cookies using Javascript. Just in case f you have no ideas what cookies can do, below are the two major usages:
- Store authentication/session: Have you notice that remember me checkbox under the login box? It uses cookie to remember you. It stores your session details so that you don't have to login when you visit the website again.
- Store data: You can use cookie to store data in client's computer. For example, Displaying a "welcome back" message or automatically fill in the username field. Or you can use it to remember the position of the current selected menu item, selected tab or position of elements
- Cookies do not use server resources since it stores in client's computer.
- Expiry date of cookies can be configured.
- Easy to implement.
- Users can delete a cookies.
- Browsers can be set to decline cookies (By default, all browsers accept cookies).
- Cookie stores data in plain text thus a potential security threat.
- It can store huge amount of data
Create, Modify and Erase Cookie
We have to understand how it works before we can go further, the structure of cookie is simple, it's made of:
- Name-value pair which stores the data.
- Expiry date, after which time the entry will be deleted.
- Web domain and path that the cookie should be associated with.
/* assume today date is 2009-09-09 */ /* Create a cookie that will expire 2 days later */ document.cookie = "name=kevin; expires=Fri, 11-Sep-2009 23:59:59 GMT; path=/"; /* Reassign value */ document.cookie = "name=queness; expires=Fri, 11-Sep-2010 23:59:59 GMT; path=/"; /* Erase a cookie, put a past date */ document.cookie = "name=queness; expires=Fri, 08-Sep-2009 23:59:59 GMT; path=/";
Cookie Functions to Make Your Life Easier
Kudos to Quirksmode.org, they have created these functions to create, read and erase cookie easily. We don't even have to remember the GMT date format, we just have to set number of days and it will do the rest for us. Pretty good huh?
function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name) { createCookie(name,"",-1); }
A Simple Implementation Menu
Alright, a really simple real implementation, it remembers which menu item you have just clicked, and the script assign a selected class to it. It highlights the current menu item.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>untitled</title> <script type="text/javascript" src="/javascript/article/Cookie_and_Javascript_How_to_Handle.php/js/jquery-1.3.1.min.js"></script> <link type="text/css" rel="stylesheet" href="/javascript/article/Cookie_and_Javascript_How_to_Handle.php/"/> <script> $(document).ready(function () { //for debugging purpose, so that you can see what is in the menu cookie $('#debug').html('Cookie Content : ' + readCookie('menu')); //if cookie menu exists if (readCookie('menu')) { //loop through the menu item $('#menu a').each(function () { //match the correct link and add selected class to it if ($(this).html() == readCookie('menu')) $(this).addClass('selected'); }); } $('#menu a').click(function () { //Set the cookie according to the text in the link createCookie('menu', $(this).html(),1); }); }); /* Cookie Function */ function createCookie(name, value, days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name) { createCookie(name,"",-1); } </script> <style> ul { padding:0; margin:0; list-style:none; } li { float:left; margin:0 10px; } li a { border-bottom:3px solid #ccc; text-decoration:none; display:block; color:#666; } li a:hover { border-bottom:3px solid #000; } li a.selected { border-bottom:3px solid #000; } .clear { clear:both; } </style> </head> <body> <ul id="menu"> <li><a href="/javascript/article/Cookie_and_Javascript_How_to_Handle.php/index.html">Home</a></li> <li><a href="/javascript/article/Cookie_and_Javascript_How_to_Handle.php/index.html">Tips</a></li> <li><a href="/javascript/article/Cookie_and_Javascript_How_to_Handle.php/index.html">Porfolios</a></li> <li><a href="/javascript/article/Cookie_and_Javascript_How_to_Handle.php/index.html">About</a></li> <li><a href="/javascript/article/Cookie_and_Javascript_How_to_Handle.php/index.html">Contact</a></li> </ul> <div class="clear"></div> <br/><br/> <div id="debug"></div> </body> </html>
- Sent (0)
- Nouveau
Générez vos vidéos d'entreprise par l'IA avec la voix ou simplement du texte
chatGPTaz.com
Parlez à ChatGPT dans votre langue maternelle
AppAIVidéo
Votre première application vidéo AI GRATUITE
Deepfake Video
Deepfake AI Video Maker
Deepfake
Deepfake AI Video Maker
AI Deep Fake
Deepfake AI Video Maker
AIvidio
AI Video Mobile Solutions
AIvideos
AI Video Platform & Solutions
AIvedio
AI Video App Maker
Artificial General Intelligence
Ai and higher level Artificial General Intelligence (AGI)
Artificial General Intelligence
Ai and higher level Artificial General Intelligence (AGI)
Faceswap AI en ligne
Échangez des visages, des vidéos, des photos et des GIF instantanément avec de puissants outils d'IA - Faceswap AI Online GRATUIT
Faceswap AI en ligne
Échangez des visages, des vidéos, des photos et des GIF instantanément avec de puissants outils d'IA - Faceswap AI Online GRATUIT
Faceswap AI en ligne
Échangez des visages, des vidéos, des photos et des GIF instantanément avec de puissants outils d'IA - Faceswap AI Online GRATUIT
Powerful AI Presentation PPT Maker for FREE
Build an impressive presentation with our free online AI presentation app
Your next top AI Assistant
Claude AI, developed by Anthropic
Your next top AI Assistant
Claude AI, developed by Anthropic
Temu gratuit 500 $ pour les nouveaux utilisateurs
Claim Free Temu $500 Credit via Affiliate & Influencer Program
Crédits publicitaires TikTok gratuits
Maîtrisez les publicités TikTok pour le marketing de votre entreprise
Dall-E-OpenAI.com
Générez automatiquement des images créatives avec l'IA
chatGPT4.win
Parlez à ChatGPT dans votre langue maternelle
Premier produit d'intelligence artificielle d'Elon Musk - Grok/UN.com
Parlez au chatbot Grok AI dans votre langue
Outily.win
Centre d'outils ouvert et gratuit, utilisable par tous et pour tous, avec des centaines d'outils
GateIO.gomymobi.com
Airdrops gratuits à réclamer et à partager jusqu'à 150 000 $ par projet
iPhoneKer.com
Économisez jusqu'à 630 $ à l'achat d'un nouvel iPhone 16
Acheter le robot Tesla Optimus
Commandez votre robot Tesla Bot : Optimus Gen 2 dès aujourd'hui pour moins de 20 000 $