I have following code:
In the file cookieSimplescont2.js
:
function criarCookie(valorCookie){
//Criar objeto data
var data = new Date();
// setando o tempo de vida do cookie
data.setTime(data.getTime()+120000);
//Criando a estrutura do Cookie
document.cookie = "primeiroCookie="+valorCookie+" ; expires="+data.toUTCString()+" ; path=/";
return "Sucesso";
}
function lendoCookie(){
return document.cookie;
}
<!DOCTYPE html>
<html>
<head>
<title>Cookies</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/estilo.css">
<script type="text/javascript" src="js/cookieSimplescont2.js"></script>
</head>
<body>
<h1>HTML SO PARA TESTES--- Testando Cookies</h1>
<button onclick="alert(criarCookie('DiaBonito'))">Criar Cookie</button>
<button onclick="alert(lendoCookie())">Lendo Cookie</button>
</body>
</html>
Well, for the LendoCookie()
function to work before I have to click Create Cookie but just because I set an expiration time of cookie
short of 2 minutes, funçãoLendoCookie()
returns the cookie
key when opening the cookieSimplescont2.html
file using IE or Firefox, but not in chrome. I've already been to the Chrome cookie settings and in the privacy field I chose the "Allow local data configuration (Recommended)" option. but even so, it does not return any value, can someone tell me why?