hea ladies and gents,
before i start, i must warn you that i have absuloutly no idea when it comes to js.
ok basically i found this code that makes an image (or in this case swf) popup on screen. The only problem is that it poped up every time the page loaded, and as i only want it to popup once per session, so i added another few lines of js that i found elsewhere so it uses cookies.
now, to the problem...
heres the js ( i have highlighted the bit i added about cookies in green, the bit i added <i guessed - dont hit me > is red and the popup js is in blue)
Code:
var key_value = "myTestCookie=true";
var foundCookie = 0;
// Get all the cookies from this site and store in an array
var cookieArray = document.cookie.split(';');
// Walk through the array
for(var i=0;i < cookieArray.length;i++)
{
var checkCookie = cookieArray[i];
// Remove any leading spaces
while (checkCookie.charAt(0)==' ')
{
checkCookie = checkCookie.substring(1,checkCookie.length);
}
// Look for cookie set by key_value
if (checkCookie.indexOf(key_value) == 0)
{
;
// The cookie was found so set the variable
foundCookie = 1;
stop()
}
}
// Check if a cookie has been found
if ( foundCookie == 0)
{
// The key_value cookie was not found so set it
document.cookie = key_value;
}
var tmr;
var t;
var obj;
function sFa() {
obj = gObj();
sLft();
shw(true);
t = 0;
sTmr();
}
function hFa() {
t = -100;
sTmr();
return false;
}
function sTmr() {
tmr = setInterval("fd()",20);
}
function fd() {
var amt = Math.abs(t+=10);
if(amt == 0 || amt == 100) clearInterval(tmr);
amt = (amt == 100)?99.999:amt;
obj.style.filter = "alpha(opacity:"+amt+")";
obj.style.KHTMLOpacity = amt/100;
obj.style.MozOpacity = amt/100;
obj.style.opacity = amt/100;
if(amt == 0) shw(false);
}
function sLft() {
var w = 300; // set this to 1/2 the width of the faw div defined in the style sheet
// there's not a reliable way to retrieve an element's width via javascript!!
var l = (document.body.innerWidth)? document.body.innerWidth / 2:document.body.offsetWidth / 2;
obj.style.left = (l - w)+"px";
}
function gObj() {
return document.getElementById("faw");
}
function shw(b) {
(b)? obj.className = 'show':obj.className = '';
}
basically i need the code to check if there a cookie and if there is, to stop the popup from showing. With the code above all works well unless there is infact a cookie, in which case it stops about half the page loading.
now if youve read this far, managed not to get confused and dont want to hit me...im sure youll be able to help
Thanks ever so much!
Ross.
|