js 获取cookie

时间:2023-03-09 02:02:45
js 获取cookie
  <!DOCTYPE html>
  <html xmlns="http://www.w3.org/1999/xhtml">
   
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <meta http-equiv="pragma" content="no-cache" />
   
  <meta http-equiv="Cache-Control" content="no-cache" />
   
  <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT" />
  <title></title>
  <script type="text/javascript">
  function getCookie(c_name) {
  if (document.cookie.length > 0) {
  c_start = document.cookie.indexOf(c_name + "=")
  if (c_start != -1) {
  c_start = c_start + c_name.length + 1
  c_end = document.cookie.indexOf(";", c_start)
  if (c_end == -1) c_end = document.cookie.length
  document.getElementById("span_id").innerHTML =unescape(document.cookie.substring(c_start, c_end))
  }
  }
   
  }
  </script>
  </head>
  <body onload="getCookie('_Yeds1216_')" style="color:green">
  cookie: <span id="span_id"></span>
  </body>
  </html>