JAVASCRIPT+iframes !!!! HELLLLP

Discussion in 'JavaScript' started by AMDERBO, Mar 8, 2007.

  1. #1
    Hi
    i'm trying to make a script that opens a random link from the page contained in an iframe after 5 seconds ....a sort of random redirection
    that's what i done :

    <head></head><body>
    <script>
    <!--
    function random_all(){
    var myrandom=Math.round(Math.random()*(document.links.length-1))
    window.location=document.links[myrandom].href
    }
    //-->
    </script>

    <a href="javascript:random_all()">Random Link</a>

    <iframe id="frame" frameborder="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" width="100%" height="100%" src="http://www.yahoo.com">

    </iframe>
    </body>


    Thanks for your help
     
    AMDERBO, Mar 8, 2007 IP
  2. bibel

    bibel Active Member

    Messages:
    289
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #2
    You want the links from inside the iframe, not the links from the current document.

    Give a name to that iframe (name="frame"), and instead of "document.links", use
    top.frames['frame'].document.links.

    Also, use setTimeout to call your function every 5 seconds
     
    bibel, Mar 8, 2007 IP