Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get full page height with Javascript?

Is there any way of getting the full page height including scrollable content?

For example, in the page below I have a height of 613px, but with a lot more content that was scrolled out. If a get the value of document.documentElement.scrollHeight it gives me the same 613px. Is there any way I can actually get the full page height?

enter image description here

EDIT:

I've tried some of the answers, but somehow, for this page I always get the same height (https://material.angular.io/). Does someone know why?

like image 690
mordecai Avatar asked Jun 29 '26 02:06

mordecai


1 Answers

This will give you a height of scrollable area too

(function() {
    let pageHeight = 0;

    function findHighestNode(nodesList) {
        for (let i = nodesList.length - 1; i >= 0; i--) {
            if (nodesList[i].scrollHeight && nodesList[i].clientHeight) {
                var elHeight = Math.max(nodesList[i].scrollHeight, nodesList[i].clientHeight);
                pageHeight = Math.max(elHeight, pageHeight);
            }
            if (nodesList[i].childNodes.length) findHighestNode(nodesList[i].childNodes);
        }
    }

    findHighestNode(document.documentElement.childNodes);

    console.log('You page hight it', pageHeight);
})();

like image 145
Anjum.... Avatar answered Jul 01 '26 15:07

Anjum....



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!