
Redireccionar si existe una cookie
Publicado por Alfredo (2 intervenciones) el 08/11/2014 14:56:14
Hola muy buenas tardes a todos! Tengo un pequeño problemilla ya que quiero redireccionar la web si existe una cookie en nuestro navegador. Os pongo el código:
cookies.js
index.html
Intenté para redireccionar poner este código en cookies.js
Pero no realiza la función :( alguien me podria ayudar?
cookies.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function GetCookie(name) {
var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen) {
var j=i+alen;
if (document.cookie.substring(i,j)==arg)
return "1";
i=document.cookie.indexOf(" ",i)+1;
if (i==0)
break;
}
return null;
}
function aceptar_cookies(){
var expire=new Date();
expire=new Date(expire.getTime()+7776000000);
document.cookie="cookies_surestao=aceptada; expires="+expire;
var visit=GetCookie("cookies_surestao");
if (visit==1){
popbox3();
}
}
$(function() {
var visit=GetCookie("cookies_surestao");
if (visit==1){ popbox3(); }
});
function popbox3() {
$('#overbox3').toggle();
}
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<html>
</head>
#overbox3 {
position: relative;
top:30%;
left: 10%;
width: 80%;
height:70%;
}
#infobox3 {
z-index:1;
margin: auto;
position: absolute;
left:26%;
top:20%;
width: 50%;
height:70%;
text-align:center;
background-color: #000;
border: 2px solid #d5ab3a;
border-radius: 25px;
}
#infobox3 img {
width:100%;
}
#infobox3 p {
color:white;
font-size: 1.2em;
text-align:center;
}
#infobox3 p a{
text-decoration: underline;
position:absolute;width:20%;float:left;left:25%;
}
</style>
<script>
$('.has-sub').click( function(e) {
e.preventDefault();
$(this).parent().toggleClass('tap');
});
}
</script>
</head>
<body>
<div id="overbox3">
<div id="infobox3">
<p>Desea aceptar politica de cookies?<a onclick='history.back()' style='cursor:pointer;'>No acepto</a><a onclick='aceptar_cookies();' style='cursor:pointer;'>Acepto</a></p>
</div>
</div>
</body>
Intenté para redireccionar poner este código en cookies.js
1
2
3
if(GetCookie("cookies_surestao") != "null"){
window.location = 'http://www.lawebdelprogramador.com/';
}
Valora esta pregunta


0