熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

javascript讀寫Cookie函數

2013-11-15 09:49:48  來源: JSP教程 

  日前看到一個別人總結的讀寫Cookie的函數想想反正自已也會用得著隨手Copy了希望新手拿去用的時候可以更好的做好項目^_^

  function GetCookieVal(offset)

  //獲得Cookie解碼後的值

  {

  var endstr = okieindexOf (; offset)

  if (endstr ==

  endstr = okielength;

  return unescape(okiesubstring(offset endstr))

  }

  function SetCookie(name value)

  //設定Cookie值

  {

  var expdate = new Date()

  var argv = SetCookiearguments;

  var argc = SetCookieargumentslength;

  var expires = (argc > ) ? argv[] : null;

  var path = (argc > ) ? argv[] : null;

  var domain = (argc > ) ? argv[] : null;

  var secure = (argc > ) ? argv[] : false;

  if(expires!=null) expdatesetTime(expdategetTime() + ( expires * ))

  okie = name + = + escape (value) +((expires == null) ? : (; expires=+ expdatetoGMTString()))

  +((path == null) ? : (; path= + path)) +((domain == null) ? : (; domain= + domain))

  +((secure == true) ? ; secure :

  }

  function DelCookie(name)

  //刪除Cookie

  {

  var exp = new Date()

  expsetTime (expgetTime()

  var cval = GetCookie (name)

  okie = name + = + cval + ; expires=+ exptoGMTString()

  }

  function GetCookie(name)

  //獲得Cookie的原始值

  {

  var arg = name + =;

  var alen = arglength;

  var clen = okielength;

  var i = ;

  while (i < clen)

  {

  var j = i + alen;

  if (okiesubstring(i j) == arg)

  return GetCookieVal (j)

  i = okieindexOf( i) + ;

  if (i == ) break;

  }

  return null;

  }


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19190.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.