I am wanting the scroll position of the document element in JavaScript, since I cannot use jQuery.
Question: What would be the JavaScript code for getting the document's vertical scroll position? I need to make it compatible as far back as IE 8 and all modern browsers.
UPDATE 1: I reviewed the 2 answers given as duplicates of this. The first one does address my problem though its not focusing on a cross-browser solution, but the second one is way off what I need. I need the vertical scroll position of document and not scrolling to the top of document. The second post talks about using a link or going step by step to top of document, which does not address my question.
UPDATE 2: Based on the answer provided by minitech, I came up with following functions to determine scroll positions that works across all modern browsers as well as upto IE 8. I tested this and it worked in Chrome, FireFox, Opera, Edge , IE 8, IE 9, IE 10 and IE 11.
function getScrollY() {
return window.scrollY || window.pageYOffset || document.body.scrollTop;
}
function getScrollX() {
return window.scrollX || window.pageXOffset || document.body.scrollLeft;
}