Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 03-04-2008, 09:39 AM javascript stop?
Junior Talker

Posts: 3
Name: Ross
Trades: 0
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.
Ross2452 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-04-2008, 01:32 PM Re: javascript stop?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Change "stop" to "break". "break" is for...well, breaking out of a loop.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 03-05-2008, 07:42 AM Re: javascript stop?
Junior Talker

Posts: 3
Name: Ross
Trades: 0
Quote:
Originally Posted by ADAM Web Design View Post
Change "stop" to "break". "break" is for...well, breaking out of a loop.
break stops it from working at all :S
Ross2452 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to javascript stop?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17782 seconds with 12 queries