www.webdeveloper.com
Results 1 to 5 of 5

Thread: Auto scrolling web content in iframe

  1. #1
    Join Date
    Nov 2008
    Posts
    3

    Auto scrolling web content in iframe

    Here's my very simple html code.

    <html><head><title>Area Forecast Discussion</title></head><body>
    <center><center><font size=6><b>Area Forecast Discussion</b></font><br>
    <iframe src="http://www.srh.noaa.gov/data/ALY/AFDALY" width="100%" height="95%" align="middle" scrolling="yes" frameborder="0"></iframe>
    </center></body></html>

    What I want to do is have the NWS data within the iframe to automatically & slowly scroll down to the bottom. That's it. I've tried a number of ways with JavaScript and all failed (I'd like it to work in IE7).

    Can anyone help?

  2. #2
    Join Date
    Apr 2008
    Posts
    85
    This is pulled from an old script I used to scroll an iFrame with buttons. It can probably be cleaned up a little more, but this should work:

    Code:
    var timer_id;
    function scroll_iframe(frm,inc,dir) {
      if (timer_id) clearTimeout(timer_id);
      if (window.frames[frm]) {
        if (dir == "v") window.frames[frm].scrollBy(0, inc);
        else window.frames[frm].scrollBy(inc, 0);
        timer_id = setTimeout("scroll_iframe('" + frm + "'," + inc + ",'" + dir + "')", 20);
      }
    }
    
    <body onLoad="scroll_iframe('frame', 1, 'v'); return true">
    
    <iframe src="http://www.srh.noaa.gov/data/ALY/AFDALY" name="frame" id="frame"></iframe>
    change the 1 to a higher number for faster scrolling, and to a negative number to scroll the other direction.
    Last edited by juststranded; 11-15-2008 at 03:03 AM.

  3. #3
    Join Date
    Nov 2008
    Posts
    3

    Still doesn't work

    Here's my new code using juststranded's script:

    <html><head><title>Area Forecast Discussion</title>
    <script language="JavaScript">
    var timer_id;
    function scroll_iframe(frm,inc,dir) {
    if (timer_id)
    clearTimeout(timer_id);
    if (window.frames[frm]) {
    if (dir == "v")
    window.frames[frm].scrollBy(0, inc);
    else
    window.frames[frm].scrollBy(inc, 0)
    timer_id = setTimeout("scroll_iframe('" + frm + "'," + inc + ",'" + dir + "')", 20);
    }
    }
    </script>
    </head><body onLoad="scroll_iframe('frame', 1, 'v'); return true">
    <center><center><font size=6><b>Area Forecast Discussion</b></font><br>
    <iframe src="http://www.srh.noaa.gov/data/ALY/AFDALY" width="100&#37;" height="95%" frameborder="0" name="frame" id="frame"></iframe>
    </center></body></html>


    When I run it, the error message doesn't like line 9 - window.frames[frm].scrollBy(0, inc); - saying "Access is denied." This is the same problem I kept having when I tried to code it myself with slightly different methods.

    Why doesn't this work?
    Last edited by RockProf; 11-15-2008 at 08:45 AM.

  4. #4
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374

  5. #5
    Join Date
    Nov 2008
    Posts
    3
    Quote Originally Posted by slaughters View Post
    Does the src of the iframe reside on a different domain ?
    http://msdn.microsoft.com/en-us/libr...28(VS.85).aspx
    Yes, the src of the iframe is from the National Weather Service. No way to autoscroll then?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles