Nada, sigue sin funcionarme. Ya he conseguido que pasando de una página a otra aparezca 'Hola hoy es día tal y son las...', pero no me sale el valor de la cookie. Posteo el código a ver qué se puede hacer, la verdad que ya estoy un poco desesperado
Código Javascript
:
Ver original<script type="text/javascript">
//prin.html, es la primera que sale y donde se tienen que coger las cookies
function getCookie(nombreCookie){
if (document.cookie.length>0){
c_start=document.cookie.indexOf(nombreCookie + "=");
if (c_start!=-1){
c_start=c_start + nombreCookie.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1){
c_end=document.cookie.length;
}
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
function setCookie(nombreCookie,valorCookie,expiredays){
var fecha=new Date();
fecha.setDate(fecha.getDate()+expiredays);
document.cookie=nombreCookie+ "=" +escape(valorCookie) + ((expiredays==null) ? "" : ";expires="+fecha.toUTCString())+"; path=/";
}
function reloj(){
var f = new Date();
var a = f.getFullYear();
var m = new Array ("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
var d = new Array ("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
var h = f.getHours();
var mi = f.getMinutes();
var s = f.getSeconds();
if (h<10){h='0'+h}
if (h>12){h=h-12}
if (mi<10){mi='0'+mi}
if (s<10){s='0'+s}
document.getElementById("capaPersonal").innerHTML = '<span style="font-size:25px;">Hola, </span><span style="font-size:30px; text-transform: capitalize;">' + nUsuario + '</span><span class="fecha">Hoy es ' + d[f.getDay()] + ', ' + f.getDate() + ' de ' + m[f.getMonth()] + ' de ' + a + ' y son las ' + h + ':' + mi + ':' + s + '</span>';
}
function checkCookie(){
nUsuario=getCookie('usuario');
if(nUsuario==null || nUsuario==""){
nUsuario=prompt('Por favor, introduce tu nombre',"");
}else{
setCookie('usuario',nUsuario,1);
}
setInterval("reloj()", 1000);
}
</script>
Código Javascript
:
Ver original<script type="text/javascript">
//formulario.html, aquí tendría que aparecer arriba lo mismo que en prin.html
function getCookie(nombreCookie){
if (document.cookie.length>0){
c_start=document.cookie.indexOf(nombreCookie + "=");
if (c_start!=-1){
c_start=c_start + nombreCookie.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1){
c_end=document.cookie.length;
}
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
function setCookie(nombreCookie,valorCookie,expiredays)
{
var fecha=new Date();
fecha.setDate(fecha.getDate()+expiredays);
document.cookie=nombreCookie+ "=" +escape(valorCookie)+
((expiredays==null) ? "" : ";expires="+fecha.toUTCString())+"; path=/";
}
function checkCookie(){
if(document.cookie.length>0){
nUsuario=getCookie('usuario');
if(nUsuario!=null || nUsuario!=""){
setCookie('usuario',nUsuario,1);
setInterval("reloj()", 1000);
}else{
document.getElementById("capaPersonal").style.display = 'none';
}
}
}
function reloj(){
var f = new Date();
var a = f.getFullYear();
var m = new Array ("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
var d = new Array ("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
var h = f.getHours();
var mi = f.getMinutes();
var s = f.getSeconds();
if (h<10){h='0'+h}
if (h>12){h=h-12}
if (mi<10){mi='0'+mi}
if (s<10){s='0'+s}
document.getElementById("capaPersonal").innerHTML = '<span style="font-size:25px;">Hola, </span><span style="font-size:30px; text-transform: capitalize;">' + nUsuario + '</span><span class="fecha">Hoy es ' + d[f.getDay()] + ', ' + f.getDate() + ' de ' + m[f.getMonth()] + ' de ' + a + ' y son las ' + h + ':' + mi + ':' + s + '</span>';
}
</script>
Código HTML:
Ver original<!---prin.html--->
Si quieres una experiencia m
ás personal de la p
ágina, haz click
<a href='#' onclick='checkCookie();' class='enlace'>aqu
í</a><!---formulario-html--->
<body onload='checkCookie();'>
Tengo más páginas pero con saber cómo hay que hacerlo con estas dos me servirá para las demás.
Saludos y gracias (: