Scroll to bottom of a textarea (Using Javascript + Safari)

Discussion in 'Mac Programming' started by Oats, Dec 12, 2006.

  1. macrumors regular

    Joined:
    Jan 8, 2003
    Location:
    New York
    #1
    Hi,
    I am actually attempting to develop a widget, where I am using a console for users to enter text, and receive a response. I am using a TEXTAREA HTML object for the main console, but I am having trouble with the scrolling. In most browsers, you can force the scroll position to the end of the textarea with this code:
    Code:
    textareaelem = document.getElementById('mytextarea');
    textareaelem.scrollTop = textareaelem.scrollHeight;
    but this doesn't work in Safari or dashboard. I don't get any javacsript errors or warnings, either. Interestingly, it does appear to work with WebKit.

    Developing a widget has so far been a VERY frustrating experience, and I have found that Safari's support for javascript leaves much to be desired, and can be very quirky, especially compared to Firefox.
     
  2. thread starter macrumors regular

    Joined:
    Jan 8, 2003
    Location:
    New York
  3. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #3
    Have you tried seeing what the values of textareaelem.scrollTop and textareaelem.scrollHeight actually are?

    Or try using a fixed number to see what the behavior might be.

    textareaelem.scrollTop = 200;

    Also, I know you don't have to but have you tried playing with the overflow CSS attribute for that textarea?
     
  4. thread starter macrumors regular

    Joined:
    Jan 8, 2003
    Location:
    New York
    #4
    I have tried some CSS modifications, currently I have this:
    Code:
    overflow-y: scroll;
    any other CSS attributes i may need to set?

    i will have to look more into what the values of those scroll variables are. is there anything I can send to re-draw the textarea? Like perhaps the scroll values are being updated fine, but just not triggering an update to redraw the control?
     
  5. thread starter macrumors regular

    Joined:
    Jan 8, 2003
    Location:
    New York
    #5
    As I enter text and scroll around the textarea manually, scrollTop always remains at 0 and never changes. The scrollHeight also stays constant at 200px, which is the initial height of the textarea, and never changes. Even if I attempt to change the value of scrollTop by setting equal to some constant number, it never changes. This works in every other browser but safari.

    Any other help or input would be very much appreciated!!
     
  6. thread starter macrumors regular

    Joined:
    Jan 8, 2003
    Location:
    New York
    #6
    It appears that Safari does not support javascript for scrolling textarea objects, only div objects.

    so here is plan B:
    create a fake keyboard event and process it, specifically a "END" keydown event which should scroll to the end of the textarea. Anyone know how to create a keydown event object and process it?
     

Share This Page