CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2010
    Posts
    42

    Keep div scrollbar scrolled to bottom at all times

    I have a bunch of information relayed to a multi-line text box from a websocket and I want my div overflow scrollbar to scroll to the bottom everytime a new line of information is recieved. The code I am using apparently works for everyone else but does not do anything for me. Any suggesions?
    Code:
    <script type="text/javascript">
        var objDiv = document.getElementById("container");
        objDiv.scrollTop = objDiv.scrollHeight;
    </script>
    <div id="container" style="border: solid; width: 70%; height: 50%; border-color: #333333; margin: 0 auto;  overflow:  auto; ">
    <div id="console_wrapper"> 
    	<pre id="console"></pre> 
    	<input type="text" name="console_input" id="console_input" value="" /> 
        <input type="submit" name="console_send" id="console_send" value="Send" /> 
        <input type="submit" name="console_quit" id="console_quit" value="Quit" />
    </div>

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Keep div scrollbar scrolled to bottom at all times

    Use scrollTo(0, 99999); instead.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Nov 2010
    Posts
    42

    Re: Keep div scrollbar scrolled to bottom at all times

    I am not that gifted with javascript. Do you mean like this?

    Code:
    <script type="text/javascript">
        document.getElementById("container").scrollTo(0, 99999);
    </script>

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Keep div scrollbar scrolled to bottom at all times

    Ah...I read your first post incorrectly and was thinking you were using an <iframe>.

    The code you have is correct. However, you need to implement it everytime data is sent/received. As you have it now, you're attempting to run it before the form and it's container is even loaded.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured