ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[±Ð¾Ç] (±Ð¾Ç²Ä28½g) ¨Ï¥Î Cookies ¤U½g

[±Ð¾Ç] (±Ð¾Ç²Ä28½g) ¨Ï¥Î Cookies ¤U½g

Ū¨úCookies
¦b¤@­ÓCookieÀɮפº¥i¥H¥]§t¦h­ÓCookies¸ê°T¡A©Ò¥H¡A·í§Ú­Ì­nŪ¨ú¬Y­ÓCookies¸ê°T®É¥i´N²Ö¤F¡A¥²¶·­n¦bCookieÀɮפº¶i¦æ·j´M¡C¦P®É¡A¤@­ÓCookies¸ê°T¸ÌÁÙ¥]§tCookiesªº¦WºÙ¤Î¥¦©Ò¥Nªíªº¸ê®Æ­È¡A§Ú­ÌÁÙ±o¤À¸Ñ¦WºÙ»P¸ê®Æ­È¡A°²³]¦b§Ú­ÌCookieÀɮפºªº¤º®e¦p¤U¡G
  1. myname=charles; age=30
½Æ»s¥N½X
¦b³o­ÓCookieÀɮפº¦³¨â­ÓCookies¡G¤@­Ó¬O¡umyname¡v¡A¥¦ªº­È¬°¡ucharles¡v¡F¥t¤@­Ó¬O¡umyname¡v¡A¥¦ªº­È¬°¡u30¡v¡A¦Ó¨â­ÓCookies¤§¶¡¬O¨Ï¥Î¤@­Ó¤À¸¹¤Î¤@­ÓªÅ¥Õ(space)¨Ó°Ï¹j¡C
¨º¦pªG§Ú­n¨ú¡umyname¡v³o­ÓCookiesªº­È¡ucharles¡v¸Ó¦p¦ó³B²z¡H

¦ì¸m·j´Mªk
§Ú­Ì¨Ó«Ø¥ß¤@­ÓÂ^¨úCookies­Èªº¨ç¦¡¡A°²³]³o­ÓÂ^¨ú¨ç¦¡ªº¦WºÙ¬°getValue()¡A·í§Ú­Ì·Q­n±oª¾¬Y­ÓCookiesªº­È®É¡A¥u­n©I¥sgetValue()¨ç¦¡¡A¦P®É¦b©I¥s®É¶Ç»¼¤@­ÓCookiesªº¦WºÙµ¹getValue()¨ç¦¡¡AgetValue()¨ç¦¡´N·|¨ú±o¦¹Cookiesªº­È¡G
CookiesÂ^¨ú¨ç¦¡
  1. function getValue(cookiesname)
  2. {
  3. cookiesname = cookiesname + ¡§=¡¨
  4. if (document.cookie.length > 0)
  5. }
  6. position = document.cookie.indexOf(cookiesname)
  7. if (position != -1)
  8. {
  9. position = position + cookiesname.length
  10. endposition = document.cookie.indexOf(¡§;¡¨ , position)
  11. if (endposition == -1)
  12. {
  13. endposition = document.cookie.length
  14. }
  15. return unescape(document.cookie.substring(position,endposition))
  16. }
  17. }
  18. return null
  19. }
½Æ»s¥N½X

  • µ{¦¡½X²Ä3¦æ¡A±N§Ú­Ì­n´M§äªºCookies¦WºÙ¦A¥[¤W¤@­Óµ¥¸¹¡u=¡v¡A¦]¬°µ¥¸¹¤§«áªº¤º®e¤~¬OCookiesªº­È¡C
  • ¦b·j´M»PÂ^¨úCookiesªº­È¤§«e¡A§Ú­Ì¥ý§PÂ_CookieÀɮפ¤¬O§_¦s¦bCookies¸ê°T¡A·íCookieÀɮתø«×¤j©ó0¡A¥NªíÀɮפº¦³Cookies¦s¦b¡A¤~¶}©l°õ¦æ·j´M»PÂ^¨úCookiesªº°Ê§@¡]µ{¦¡½X²Ä4¦æ¡^¡C
  • µ{¦¡½X²Ä5¦æ¡A±µµÛ§Q¥ÎindexOf()¨ç¦¡¶}©l·j´MCookiesªº¦ì¸m¡A¨Ã±N·j´M«áªºCookies¦WºÙ¦ì¸m³]©wµ¹ÅܼÆposition¡C
  • µ{¦¡½X²Ä6¦æ¡A¥ý§PÂ_·j´MCookies¦WºÙªºµ²ªG¡A¦pªGÅܼÆposition¤£µ¥©ó-1¡A¥Nªí§Ú­Ì­n·j´MªºCookies¦s¦b¡A¦¹®É¤~¶}©l¶i¦æCookies­ÈªºÂ^¨ú¤u§@¡C
  • µ{¦¡½X²Ä8¦æ¡A¬°¦ó­n±NpositionÅܼƭȥ[¤WCookies¦WºÙ¡]²{¦b¬O¡GCookies¦W=¡^ªºªø«×¡H¦]¬°µ¥¸¹¤§«áªº¤º®e¤~¬OCookiesªº­È¡ApositionÅܼƭȥ[¤WCookies¦WºÙªºªø«×¡A¤~¬OÂ^¨úCookies­Èªº°_©l¦ì¸m¡I
  • µ{¦¡½X²Ä9¦æ¡A¨M©wÂ^¨úCookies­Èªº²×¤î¦ì¸m¡A¦]¬°¨C­ÓCookiesªº§ÀºÝ³£·|¦³¤@­Ó¤À¸¹¡u¡F¡v§@¬°µ²§ôÂI¡A©Ò¥H¡A§Ú­Ì¥u­n¥ÑCookies­Èªº°_©l¦ì¸m©¹«á§ä¨ì¤À¸¹¡A´N¥i±o¨ìCookies­Èªº²×¤î¦ì¸m¡C
  • µ{¦¡½X²Ä10¨ì13¦æ¡A³o¬O¹w¨¾§Ú­Ì­n§äªºCookies­è¦n¬O¥þ³¡Cookies¤¤ªº³Ì«á¤@­Ó¡A¦pªG¬O³Ì«á¤@­Ó¡A¨º»òCookies­Èªº§ÀºÝ´N¤£·|¦³¤@­Ó¤À¸¹¡u¡F¡v¡A©Ò¥HCookies­Èªº²×¤î¦ì¸m´N­è¦n¬OCookieÀɮתºªø«×¡C
  • µ{¦¡½X²Ä14¦æ¡AÂ^¨úCookies­È°_©l¦ì¸m¦ÜCookies­È²×¤î¦ì¸mªºCookies­È¡C


¹ê¨Ò¾Ç²ß¡G
±N¼g¤JªºÂsÄýªÌ©m¦WÂ^¨ú¥X¨Ó¡C
  1. <HTML>
  2. <HEAD>
  3. <TITLE>Â^¨úCookies</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <SCRIPT Language="JavaScript">
  7. //Cookies­ÈÂ^¨ú¨ç¦¡
  8. function getValue(cookiesname)
  9. {
  10. cookiesname = cookiesname + "="
  11. if (document.cookie.length > 0)
  12. {
  13. position = document.cookie.indexOf(cookiesname)
  14. if (position != -1)
  15. {
  16. position = position + cookiesname.length
  17. endposition = document.cookie.indexOf(";" , position)
  18. if (endposition == -1)
  19. {
  20. endposition = document.cookie.length
  21. }
  22. return unescape(document.cookie.substring(position,endposition))
  23. }
  24. }
  25. return null
  26. }

  27. //©I¥sCookies­ÈÂ^¨ú¨ç¦¡
  28. name=getValue("username")
  29. //±N¨ú¥XªºCookiesÅã¥Ü¥X¨Ó
  30. alert ("§Aªº¦W¦r¬O:" + name)

  31. </SCRIPT>
  32. </BODY>
  33. </HTML>
½Æ»s¥N½X


       ´£¥Ü¡I¡I
Escape¨ç¦¡·|±N¯S®í¦r¤¸©Î²Å¸¹¥H¹ïÀ³ªºescape¦r¦ê´À¥N¡A­Y§Ú­Ì­nÁÙ­ì³o¨Ç¯S®í¦r¤¸©Î²Å¸¹«h¥i¥H¨Ï¥Îunscape¨ç¦¡±N¨äÁÙ­ì¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

§R°£Cookies
­n±NCookies§R°£¤èªk«Ü²³æ¡A¥u­n±NCookiesªº¨ì´Á¤é³]©w¬°¡u¹L¥hªº¤é´Á¡v§Y¥i¡A©Ò¿×ªº¡u¹L¥hªº¤é´Á¡v´N¬O¤ñ§A¥Ø«e¨t²Î®É¶¡ÁÙ¦­ªº¤é´Á°Õ¡I¦ý¬O¡A§A©Ò­n§ó·sªºCookies¦WºÙ¥²¶·»P§A­n§R°£ªºCookies¦WºÙ¬Û¦P¡I

°²³]§Aªº¾÷¾¹¸Ì¦³¤@­ÓCookies¥¦ªº¦WºÙ¬OtestCookies¡A²{¦b§A­n§â¥¦§R°£¤F¡G
  1. cookiesname=¡¨testCookies¡¨
  2. deltime=¡¨Thu, 29 Sep 1990 00:00:01 GMT¡¨
  3. document.cookie = cookiesname + ¡¨=; expires=¡¨ + deltime
½Æ»s¥N½X
ª`·N³á¡IdeltimeÅܼƤºªº¤é´Á¬O®æªL«Âªv®æ¦¡¡A¦Ó¥B¬O­n¤ñ§A¨t²Î®É¶¡§ó¦­ªº¤é´Á¡C

¦pªG§Aı±o¨C¦¸§R°£Cookies³£­n¼g¤@ªø¦êªº¤é´Á«Ü·Ð¡A¨º´N§â§R°£Cookiesªº±Ô­z¼g¦¨¤@­Ó¨ç¦¡§a¡I·í§A­n§R°£Cookiesªº®É­Ô¡A´N©I¥s¨ç¦¡¨Ã¶Çµ¹¨ç¦¡¤@­ÓCookies¦WºÙ´N¥i¥H±N¸ÓCookies§R°£¤F¡A¦p¤U­±³o­Óclear()¨ç¦¡¡G
  1. function clear(cookiesname)
  2. {
  3. document.cookie = cookiesname + ¡¨=; expires= Thu, 29 Sep 1990 00:00:01 GMT¡¨
  4. }
½Æ»s¥N½X
clear()¨ç¦¡¥u¬O±N§A·Q§R°£ªºCookies­È²M°£¡A¨Ã§â¨ì´Á¤é³]©w¬°¥H«eªº®É¶¡¦Ó¤w¡A§A¤£­n¥H¬°³o¼ËCookies´N¤£¨£¤FËç¡IÁÙ­nµ¥§A±NÂsÄý¾¹Ãö³¬¤§«á¡A¥¦¤~·|¯u¥¿ªº®ø¥¢¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : §Ñ¥\¤£§Ñ¹L¡A§Ñ«è¤£§Ñ®¦¡C
ªð¦^¦Cªí ¤W¤@¥DÃD