1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with Javascript....

Discussion in 'HTML & JavaScript' started by luckykittypurrpurr, Feb 6, 2009.

  1. luckykittypurrpurr

    luckykittypurrpurr Registered Member

    Joined:
    Aug 20, 2008
    Messages:
    72
    Likes Received:
    48
    sorry edited out, hopefully mods can remove
    i realized the answer was right in front of me. sorry again! please remove
     
    Last edited: Feb 6, 2009
  2. luckykittypurrpurr

    luckykittypurrpurr Registered Member

    Joined:
    Aug 20, 2008
    Messages:
    72
    Likes Received:
    48
    Ok nevermind, I still do have the problem. I thought I fixed it but I didn't.

    I am trying to have a an iframe come up, in order, everytime the page is either opened or refreshed.

    i tried this code, but it won't loop the array IN ORDER which is what I need....

    then i tried this one, but for some reason the same iframe is coming up every time i refresh it....
    Code:
    var iframeAds = new Array(
        'iframe code A',
        'iframe code B',
        'iframe code C'
    );
    
    for (value = 0; value < iframeAds.length; value++){
        document.write( iframeAds[0] );
    }
    I am not good at javascript and not really sure what im doing... so any specific help would be great. I dont have any access to server side, so i really need some javascript code.

    thanks in advance for anyone who has the solution....
     
  3. justthinking

    justthinking BANNED BANNED

    Joined:
    Aug 13, 2008
    Messages:
    475
    Likes Received:
    463
    Could you explain exactly what you mean by this? Are you trying to index through the array randomly or actually index through it?

    Edit: I think the problem is that the math.random() will only return a number between 0 and 1.

    In your second attempt, the same offer in the array will always show iframeAds[0]. You never index the array. Off the top of my head I would try iframeAds[value].
     
    • Thanks Thanks x 1
    Last edited: Feb 7, 2009
  4. 195471

    195471 Regular Member

    Joined:
    Oct 11, 2008
    Messages:
    417
    Likes Received:
    260
    I just found something cool that I think may be helpful to you:

    Code:
    http://coolwebdeveloper.com/2008/08/building-a-javascript-ad-rotator-slideshow-with-123-buttons-play-pause-and-stop-options/
    It's a javascript ad rotator. Out of the box, it doesn't use iframes, but you can simply replace the image code with your iframe code and it should work fine, as I just tested it.

    The only other thing that you may need to work on is the rndm function, which changes the rotation pattern every time the page is refreshed or reloaded. I commented out lines 19-21 in slideshow.js, and this caused the content to be rotated in the same order every time, which I believe is what you're looking for.

    The site offering the code is doing so for free, but it requires an opt-in. I have provided both the original code and my modification of it that will hopefully be of use to you:

    Code:
    http://www.mediafire.com/?sharekey=258b72aa322c03546e7203eb87368129e04e75f6e8ebb871
     
    • Thanks Thanks x 1
  5. luckykittypurrpurr

    luckykittypurrpurr Registered Member

    Joined:
    Aug 20, 2008
    Messages:
    72
    Likes Received:
    48
    Im trying to index through it. 1 by 1. each refresh and page load would bring up a different iframe in order.

    Thanks 195471, i am going to try it out right now and ill get back and let you know how it worked. I am pretty sure its the solution, hopefully i can apply it (im totally new with javascripting).
     
  6. luckykittypurrpurr

    luckykittypurrpurr Registered Member

    Joined:
    Aug 20, 2008
    Messages:
    72
    Likes Received:
    48
    checked it out and i havent even a clue what to do with the 3 files. i looked at it on the webpage, like the opt in and its like a slideshow, which isnt what im looking for.

    i dont want it to change on a timer or anything. i just like it to do exactly what it does in the first code i posted, just in order instead of random.

    about the 3 files, i open them and im completely overwhelmed, i have no idea what to even do with them. i really need a code like the 2 i posted where i can insert in my html file for my website.

    on the second code i posted, i did switch out 0 with value but it just shows all 3 iframes at the same time like in a column.

    ok so basically what im looking for is a script i can cut and paste in my index.html file that will change between 3 iframes in order when the page is viewed or reloaded.

    so it would be like

    1st view/reload= iframe1
    2nd view/reload= iframe2
    3rd view/reload= iframe3
    4st view/reload= iframe1
    5nd view/reload= iframe2
    6rd view/reload= iframe3 etc

    or instead, maybe there is a code (that isnt server side) that can forward a url to a different url every time its viewed like

    so first time domain1.com is viewed itll get forwarded to domain2.com
    next time its viewed itll get forwarded to domain3.com
    3rd time- domain4.com
    4th time- domain2.com
    5th time- domain3.com
    6th time- domain4.com etc

    whichever way, its just important it does it in order, without having to do anything to server side, any ideas?
     
    Last edited: Feb 7, 2009
  7. 195471

    195471 Regular Member

    Joined:
    Oct 11, 2008
    Messages:
    417
    Likes Received:
    260
    Ah, okay. I misunderstood (obviously). If you want to display the iframes in sequential order, then it looks like you'll need a way to keep track of the last iframe that was loaded. I had no luck finding code for a non-random rotator, but the closest thing I found was this thread:

    Code:
    http://forums.asmallorange.com/index.php?showtopic=12366&pid=78572&mode=threaded&start=#entry78572
    So according to the above, you'd need to either create a text file or database to store data regarding iframe loads.
     
  8. 195471

    195471 Regular Member

    Joined:
    Oct 11, 2008
    Messages:
    417
    Likes Received:
    260
    Okay, forget the text file solution. You can do this very easily with a cookie instead...

    index.html:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script language="javascript" type="text/javascript">
    <!--
    var iframes= new Array();
    iframes[0]="http://www.google.com";
    iframes[1]="http://www.yahoo.com";
    iframes[2]="http://www.msn.com";
    
    function setCookie() {
    num=num+1;
    if(num>2) { // the number entered after the ">" must equal the highest number in the array above
    num=0;
    }
    var which = "iframes["+num+"]";
    var now = new Date();
    now.setTime(now.getTime() + 30*24*60*60*1000);
    var expString = "; expires=" + now.toGMTString();
    document.cookie = "Iframe_="+which+expString;
    }
    
    function setIframe() {
    if (/Iframe_=iframes\[(\d*)\]/.test(document.cookie)) {
    document.getElementById("iframes").src =iframes[RegExp.$1*1];
    num=RegExp.$1*1;
    setCookie();
    }
    else {
    document.getElementById("iframes").src =iframes[0];
    num=0;
    setCookie();
    }
    }
    //-->
    </script>
    </head>
    
    <body onLoad="setIframe();">
    <iframe id="iframes" src="" width="500" height="300" scrolling="no" frameborder="0"></iframe>
    </body>
    </html>
    Edit: The code above is my modification of the code here:

    Code:
    http://www.webdeveloper.com/forum/archive/index.php/t-68325.html
     
    Last edited: Feb 8, 2009
  9. luckykittypurrpurr

    luckykittypurrpurr Registered Member

    Joined:
    Aug 20, 2008
    Messages:
    72
    Likes Received:
    48
    wow thanks so much! ill test it out right now :)
     
  10. luckykittypurrpurr

    luckykittypurrpurr Registered Member

    Joined:
    Aug 20, 2008
    Messages:
    72
    Likes Received:
    48
    just tested it. thank you so much, it works perfectly! you are genius!! (((((((((((hugs))))))))))))

    i have some methods and ideas im currently working out and if i need scripting for it i know who to pm and ill pay you generously of course :) lets just hope i can work the methods out first! LOL
     
  11. 195471

    195471 Regular Member

    Joined:
    Oct 11, 2008
    Messages:
    417
    Likes Received:
    260
    Aw, shucks. :)

    I'm glad this works for you. That was quite an interesting problem that you presented, and it got me thinking about how I might use such a script in the future. Have fun with your project! :)