Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling anchors within Inline frames

    First post ever!

    I'm trying to make a little scheme work correctly. It may be that my abilities just aren't there yet, being an amateur at this.

    Basically I want to have an inline frame serve as a marquee. I'm trying to get my function to load the frame page and jump down to different anchors to display a short text passage (actually, it will be a caption to a slideshow that's just above the iframe).

    This is the relevant code I have in the head (it's probably flawed):

    myPix = new Array("1.jpg","2.jpg","3.jpg")
    myCaptions = new Array("captions.htm#1","captions.htm#2","captions.htm#3")
    thisSlide = 0
    imgCt = myPix.length - 1

    function Next() {
    if (document.images && thisSlide < imgCt) {
    thisSlide++
    document.Pictures.src=myPix[thisSlide]
    document.Captions.src=myCaptions[thisSlide]
    }}


    And the body:

    <img src="1.jpg" name="Pictures"></p>
    <iframe src="captions.htm" name="Captions" height="100" width="500" scrolling="no"></iframe>

    <a href="javascript:Next()">Next</a>




    So for each new picture, I wanted the frame to jump down to the captions listed in the array. (Instead it just stays at the top, so something's definitely wrong.)

    Thanks to anyone who can help.
    Last edited by chimly; 01-16-2005 at 10:04 PM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Try changing this:

    document.Captions.src=myCaptions[thisSlide]

    to:

    window.frames['Captions'].location.href=myCaptions[thisSlide];

    But why not simply use a div tag instead of iframe?
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var myPix = new Array(
     ["1.jpg", "caption 1"],
     ["2.jpg", "caption 2"],
     ["3.jpg", "caption 3"]
    );
    
    var thisSlide = 0;
    var imgCt = myPix.length;
    
    function Next() {
      if (thisSlide < imgCt) {
        document.images['Pictures'].src = myPix[thisSlide][0];
        document.getElementById('Caption').innerHTML = myPix[thisSlide][1];
        thisSlide++;
      }
      return false;
    }
    </script>
    <style type="text/css">
    #Caption {
      font: bold 10pt Verdana;
      color: blue;
    }
    </style>
    <body onload="Next()">
    <p><img src="1.jpg" name="Pictures"></p>
    <div id="Caption"></div>
    
    <a href="#" onclick="return Next()">Next</a>
    </body>
    </html>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •