Figuring out where user is scrolled in an iframe

Discussion in 'Javascript' started by FunGuySF, Jan 17, 2005.

  1. FunGuySF

    FunGuySF Guest

    I have some content in a scrollable iframe. I update this content every 5
    seconds using setInterval(). After updating the contents, I force the
    window to scroll to the bottom (scrollBy), where I've placed the most
    current content. The window is scrollable, so the user can scroll to the
    top (older content) and read it if they wish. The code does add new content
    to the bottom and scroll to the bottom... here it is:

    function refreshContent(newContent) {
    var tr, td;
    tbody = parent.frameContent.bodyContent;

    // Add new content at the bottom
    for (var i = 0; i < newContent.length; i++) {
    tr = tbody.insertRow(tbody.rows.length);
    td = tr.insertCell(tr.cells.length);
    td = tr.insertCell(tr.cells.length);
    }

    // scroll to bottom of chat window
    parent.frmChat.scrollBy(0,10000);
    }

    Here's the problem. If a user has scrolled to the top of the window to
    read, when the Interval kicks off, they are shot down to the bottom of the
    page again, and lose their place. Is there some way for me to check if the
    user is reading the window (i.e., not scrolled to the bottom), and skip the
    scrollBy? Something like:

    // check window scrollPosition before adding new text
    scrollPosition = ??????;

    // Add new content at the bottom
    [...]

    // scroll to bottom of chat window, if it was at the bottom before I
    added content
    if ( scrollPosition == [BOTTOM] ) {
    parent.frmChat.scrollBy(0,10000);
    }

    Any ideas?

    Thanks!

    Mike
     
    FunGuySF, Jan 17, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darrel
    Replies:
    19
    Views:
    614
    darrel
    Jan 30, 2006
  2. Dale
    Replies:
    4
    Views:
    378
  3. Flip
    Replies:
    8
    Views:
    701
  4. rboelio
    Replies:
    1
    Views:
    357
    Andrew Thompson
    Feb 3, 2004
  5. Roshan Pai
    Replies:
    1
    Views:
    453
    bugbear
    Oct 7, 2004
Loading...

Share This Page