無明居

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            10 隨筆 :: 0 文章 :: 1 評(píng)論 :: 0 Trackbacks
          ??1 // ?utility?function?to?retrieve?an?expiration?date?in?proper
          ??2
          ??3 // ?format;?pass?three?integer?parameters?for?the?number?of?days,?hours,
          ??4
          ??5 // ?and?minutes?from?now?you?want?the?cookie?to?expire?(or?negative
          ??6
          ??7 // ?values?for?a?past?date);?all?three?parameters?are?required,
          ??8
          ??9 // ?so?use?zeros?where?appropriate
          ?10
          ?11 function ?getExpDate(days,?hours,?minutes)? {
          ?12
          ?13 ???? var ?expDate? = ? new ?Date(?);
          ?14
          ?15 ???? if ?( typeof ?days? == ? " number " ? && ? typeof ?hours? == ? " number " ? && ?
          ?16
          ?17 ???????? typeof ?hours? == ? " number " )? {
          ?18
          ?19 ????????expDate.setDate(expDate.getDate(?)? + ?parseInt(days));
          ?20
          ?21 ????????expDate.setHours(expDate.getHours(?)? + ?parseInt(hours));
          ?22
          ?23 ????????expDate.setMinutes(expDate.getMinutes(?)? + ?parseInt(minutes));
          ?24
          ?25 ???????? return ?expDate.toGMTString(?);
          ?26
          ?27 ????}

          ?28
          ?29 }

          ?30
          ?31 ???
          ?32
          ?33 // ?utility?function?called?by?getCookie(?)
          ?34
          ?35 function ?getCookieVal(offset)? {
          ?36
          ?37 ???? var ?endstr? = ?document.cookie.indexOf?( " ; " ,?offset);
          ?38
          ?39 ???? if ?(endstr? == ? - 1 )? {
          ?40
          ?41 ????????endstr? = ?document.cookie.length;
          ?42
          ?43 ????}

          ?44
          ?45 ???? return ?unescape(document.cookie.substring(offset,?endstr));
          ?46
          ?47 }

          ?48
          ?49 ???
          ?50
          ?51 // ?primary?function?to?retrieve?cookie?by?name
          ?52
          ?53 function ?getCookie(name)? {
          ?54
          ?55 ???? var ?arg? = ?name? + ? " = " ;
          ?56
          ?57 ???? var ?alen? = ?arg.length;
          ?58
          ?59 ???? var ?clen? = ?document.cookie.length;
          ?60
          ?61 ???? var ?i? = ? 0 ;
          ?62
          ?63 ???? while ?(i? < ?clen)? {
          ?64
          ?65 ???????? var ?j? = ?i? + ?alen;
          ?66
          ?67 ???????? if ?(document.cookie.substring(i,?j)? == ?arg)? {
          ?68
          ?69 ???????????? return ?getCookieVal(j);
          ?70
          ?71 ????????}

          ?72
          ?73 ????????i? = ?document.cookie.indexOf( " ? " ,?i)? + ? 1 ;
          ?74
          ?75 ???????? if ?(i? == ? 0 )? break ;?
          ?76
          ?77 ????}

          ?78
          ?79 ???? return ? "" ;
          ?80
          ?81 }

          ?82
          ?83 ???
          ?84
          ?85 // ?store?cookie?value?with?optional?details?as?needed
          ?86
          ?87 function ?setCookie(name,?value,?expires,?path,?domain,?secure)? {
          ?88
          ?89 ????document.cookie? = ?name? + ? " = " ? + ?escape?(value)? +
          ?90
          ?91 ????????((expires)? ? ? " ;?expires= " ? + ?expires?:? "" )? +
          ?92
          ?93 ????????((path)? ? ? " ;?path= " ? + ?path?:? "" )? +
          ?94
          ?95 ????????((domain)? ? ? " ;?domain= " ? + ?domain?:? "" )? +
          ?96
          ?97 ????????((secure)? ? ? " ;?secure " ?:? "" );
          ?98
          ?99 }

          100
          101 ???
          102
          103 // ?remove?the?cookie?by?setting?ancient?expiration?date
          104
          105 function ?deleteCookie(name,path,domain)? {
          106
          107 ???? if ?(getCookie(name))? {
          108
          109 ????????document.cookie? = ?name? + ? " = " ? +
          110
          111 ????????????((path)? ? ? " ;?path= " ? + ?path?:? "" )? +
          112
          113 ????????????((domain)? ? ? " ;?domain= " ? + ?domain?:? "" )? +
          114
          115 ???????????? " ;?expires=Thu,?01-Jan-70?00:00:01?GMT " ;
          116
          117 ????}

          118
          119 }

          120
          121
          posted on 2006-07-04 22:52 無明 閱讀(256) 評(píng)論(0)  編輯  收藏 所屬分類: 收藏夾

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 吴川市| 丰都县| 武陟县| 射洪县| 沂源县| 鸡西市| 永德县| 太仓市| 阳东县| 安顺市| 定边县| 乐都县| 偃师市| 渝北区| 随州市| 定安县| 茌平县| 旺苍县| 云梦县| 武宣县| 永川市| 霍邱县| 叶城县| 南木林县| 太保市| 陵水| 武鸣县| 辽中县| 武邑县| 清新县| 浑源县| 连州市| 葵青区| 栾川县| 富平县| 介休市| 福州市| 广丰县| 绥阳县| 塔河县| 金坛市|