get-cookie.js

来自「这是《JavaScript学习源代码》一书的源代码」· JavaScript 代码 · 共 34 行

JS
34
字号
// find any cookies
if( window.document.cookie )
{  

  // unescape the cookie data  
  var cookiedata = unescape( window.document.cookie );
  
  // split the name=value pairs  
  var userdata = cookiedata.split( "=" );
  
  // if the cookie is called cookiedata  
  if( userdata[0] == "cookiedata" )  
  {                          
    // split the comma delimited values    
    var data = userdata[1].split( "," );    
    var user = data[0];    
    var acct = data[1];

    // display the data retrieved from the cookie
    alert("Welcome " + user + "\nAccount number: " + acct);  
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?