<!DOCTYPE html> <html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var cookies = {}; function leerCookies() { var c = document.cookie; c = c.split(";"); for (var i = 0; i < c.length; i++) { var t = c[i].split("="); cookies[t[0].trim()] = t[1]; } } function checkCookies() { leerCookies(); if (cookies.usuario != undefined) { document.getElementById("usuario").value = cookies.usuario; } if (cookies.fecha != undefined) { document.getElementById("acceso").innerHTML = "Último acceso: " + cookies.fecha; } } function guardar() { var c = document.getElementById("usuario").value; var f = new Date().toLocaleString(); document.cookie = "usuario=" + c + "; expires=tue, 09 february 2016 9:40:00 UTC;path=/"; document.cookie = "fecha=" + f + "; expires=tue, 09 february 2016 9:40:00 UTC;path=/"; } </script> </head> <body onload="checkCookies()"> <form action="index.html" method="POST"> <input type="text" id="usuario"> <input type="password" name="pass"> <input type="submit" onclick="guardar()"> <div id="acceso"></div> </form> </body> </html>