Detect when user comes to end of readonly text field on html page

I need to determine when the user comes to the end of readonly textarea in the html page.

A very long log for the application will be displayed in the text box. The log files are so large that it is not possible to download all the text in one go (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 next to the last line of the loaded text , to give him the next n lines through an ajax call.

What is the best way to detect this event?

+7
javascript events textarea
source share
2 answers

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

+2
source share

You can work with the position of the carriage (checking where it is and comparing it with your length).

Or you can work with the scroll bar . (or a combination of both)

+1
source share

All Articles