Overcoming Challenges in Document Height Calculation with JavaScript
Determining the height of a document with JavaScript presents difficulties on certain websites. On platforms such as Fandango and Paperback Swap, various JavaScript methods fail to yield accurate results.
The Problem
The Solution: A Comprehensive Approach
To accurately determine document height, a comprehensive approach is required:
var body = document.body, html = document.documentElement; var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );
This code calculates the maximum height value from all available options:
Considerations
The above is the detailed content of Why Is Determining Document Height in JavaScript So Difficult, and What\'s the Reliable Solution?. For more information, please follow other related articles on the PHP Chinese website!