Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect when a user arrives at the end of a readonly textarea in an html page

I need to detect when a user arrives at the end of a readonly textarea in an html page.

The textarea will display a very long log for an application. The logs files are so big that is impossible to load all the text in one time (some log files are almost 200 MB). So I will load the first, say, 1000 lines, and then I need to detect when the user is near the last line of the loaded text to give him the next n lines via an ajax call.

What is the best way to detect this event?

like image 247
alexmeia Avatar asked Feb 18 '10 10:02

alexmeia


2 Answers

You should compare the textarea.scrollHeight to the textarea.scrollTop - the closer they are, the closer you are to the end of your text area.

like image 197
Alex Sexton Avatar answered Nov 15 '22 00:11

Alex Sexton


You could work with the caret position (checking where it is and comparing it to your length).

Or, you could work with the scrollbar position. (or a combination of both)

like image 38
Blair McMillan Avatar answered Nov 15 '22 00:11

Blair McMillan