How Do I Detect the Scroll Length of a Page?

You must use JavaScript in your HTML Web pages to determine the scroll length of a user's browser window. You can retrieve the horizontal and vertical scroll lengths. Programmers determine scroll length when they want to automatically scroll up and down or left and right. The "innerHeight" and "innerWidth" functions are used to retrieve these values.

Instructions

    • 1

      Right-click the HTML file you want to edit. Click the pop-up window's "Open With" option. In the list of programs shown, double-click your preferred HTML editor.

    • 2

      Add the "script" tag to the top of your HTML file. The script tag defines a block of JavaScript code. Copy and paste the following code to your HTML:

      <script type="text/javascript"> </script>

    • 3

      Type the following code between the new script tags to detect the scroll length:

      var width = window.innerWidth;

      var height = window.innerHeight;

    • 4

      Display the results. You can use the "alert" function to test the new JavaScript code. Type the following code to display the scroll length variables:

      alert(width);

      alert(height);

Related Searches:

References

Comments

Related Ads

Featured