Red de conocimiento informático - Material del sitio web - Cómo usar js para obtener el valor de la cookie

Cómo usar js para obtener el valor de la cookie

lt;!DOCTYPE?HTMLgt;

lt;html?lang="en-US"gt;

lt;headgt;

lt;meta?charset ="UTF-8"gt;

lt;meta?name = "palabras clave"?content="Repollo Editorial"gt;

lt;titlegt;Repollo Editoriallt;/titlegt;

lt;style?type="text/css"gt;

lt;/stylegt;

lt;script?type="text/javascript" gt;

función?readCookie?(nombre)

{

var?cookieValue?=?""

var?búsqueda ?=?nombre? ?" =";

if(document.cookie.length?gt;?0)

{

desplazamiento?=?documento .cookie.indexOf?if (offset!=-1)

{

offset? =?search.length;

end?=?document.cookie .indexOf?(";",?offset);

if (end?==-1)

end?=?document.cookie.length;

cookieValue?=?subring(offset, end))

}

}

return?cookieValue;

}

función?writeCookie?horas)

{

var?horas?*?3600000);

¿caducar?=?" ; caduca ="? ?expire.toGMTString?();

}

document.cookie?=?nombre? ?escape?(valor)? ?expire;

}

escribirCookie?("miCookie", ?" mi?nombre", ?24);

alerta?(leerCookie?("miCookie"));

lt;/scriptgt;

lt;/headgt;

lt;/bodygt;

lt;/body gt;

lt;/htmlgt;