/    Sign up×
Community /Pin to ProfileBookmark

Dynamic iFrame Loading

Hey everyone,

I’m setting up a website, and I’m having some javascript issues. I need a script which will do the following:

  • 1. (Externally, as in, not from within the iFrame itself) load a random page into an iFrame

  • 2. Every 15 seconds, load a new random page
  • I’ve written up a basic script so far, but it doesn’t work. What am I doing wrong? (My iFrame is called sky). This script should load the random page and I have not added the timer reload yet.

    <script type=”javascript”>
    function PageLoad();
    {
    url_array=new Array()
    url_array[1]=”link1″
    url_array[2]=”link2″
    url_array[3]=”link3″
    url_array[4]=”link4″
    url_array[5]=”link5″
    url_array[6]=”link6″
    url_array[7]=”link7″
    url_array[8]=”link8″
    url_array[9]=”link9″
    url_array[10]=”link10″

    var page=Math.floor(Math.random()*10+1)

    document.sky.main.src=page
    }
    </script>

    Thanks for any help

    to post a comment
    JavaScript

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @slaughtersOct 09.2009 — Your array elements are not web page file names, they appear just to be names, they should at least end in ".html"

    You are assigning a random number (page) to be the source of your iframe. It needs to be an actual HTML page, not the number.

    The syntax you are using to assign it is not correct. If your iframe tag has an ID='sky' in it then you could do it something like this:
    [CODE]url_array=new Array();
    url_array[1]="link1.html";
    .
    .
    .
    url_array[10]="link10.html";

    var page=Math.floor(Math.random()*10+1);

    document.getElementByID('sky').src = url_array[page];[/CODE]
    ×

    Success!

    Help @Marc_Steene spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...