Hei! Minulla on ongelmia evästeiden lukemisessa javascriptillä. Tarkoitus olisi, että sivulle saavuttaessa sivu tarkistaisi, että sinulta löytyy oikea eväste, jonka sisältö on myös oikea. Jos evästettä ei olisi tai sen sisältö olisi väärin sivuja selaileva vierailija ohjattaisiin etusivulle. Yritin itse koodailla tuota, mutta koodi ei vain toiminut. Olisin todella iloinen, jos joku osaisi auttaa minua.
Koodini on siis tällainen (poistin < ja > -merkit, jottei suomi24 sekoilisi):
html
head
title Hieno sivuni /title
script type="text/javascript" language="JavaScript"
function tarkistus()
{
var sisalto = getCookie("lu0");
if (sisalto == null) {
parent.location="index.html";
}
else if (lu0 == "XV777") {
return false;
}
else {
parent.location="index.html";
}
}
function getCookie(name)
{
var search = Name "="
if (document.cookie.length > 0)
{ // if there are any cookies
offset = document.cookie.indexOf(search)
if (offset != -1)
{ // if cookie exists
offset = search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset)
// set index of end of cookie value
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
}
/script
/head
body onLoad="tarkistus();"
Sivun sisältöä...
/body
/html
Koodini on siis tällainen (poistin < ja > -merkit, jottei suomi24 sekoilisi):
html
head
title Hieno sivuni /title
script type="text/javascript" language="JavaScript"
function tarkistus()
{
var sisalto = getCookie("lu0");
if (sisalto == null) {
parent.location="index.html";
}
else if (lu0 == "XV777") {
return false;
}
else {
parent.location="index.html";
}
}
function getCookie(name)
{
var search = Name "="
if (document.cookie.length > 0)
{ // if there are any cookies
offset = document.cookie.indexOf(search)
if (offset != -1)
{ // if cookie exists
offset = search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset)
// set index of end of cookie value
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
}
/script
/head
body onLoad="tarkistus();"
Sivun sisältöä...
/body
/html
Vastaukset
Vanhimmat
Ei vielä vastauksia
Aloittaja odottaa vastauksia. Kerro oma näkemyksesi ensimmäisenä.