Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. Getting the page height

Getting the page height

Scheduled Pinned Locked Moved Web Development
csharpasp-net
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brendan Vogt
    wrote on last edited by
    #1

    Hi, I am trying to get the height of the page after the page loads everything, I currently used document.body.scrollHeight but now it keeps on returning 0, no matter in want page event I add it. I am using ASP.NET 2.0. Thanks

    C 1 Reply Last reply
    0
    • B Brendan Vogt

      Hi, I am trying to get the height of the page after the page loads everything, I currently used document.body.scrollHeight but now it keeps on returning 0, no matter in want page event I add it. I am using ASP.NET 2.0. Thanks

      C Offline
      C Offline
      Craig G Fraser
      wrote on last edited by
      #2

      The method to get the height differs depending in what browser you are using. I have a javascript function that i use to center an element on a screen. This determines the browser being used and uses the correct method accordingly. Hope this helps.

      // centers an element on the screen
      function centerElement(element, left, top)
      {
      var x = document.body.scrollWidth;
      var y = document.body.scrollHeight;
      if (getBrowser().indexOf('IE') == 0)
      {
      x = document.documentElement.clientWidth;
      y = document.documentElement.clientHeight;
      }
      x = (x / 2) + document.body.scrollLeft - (element.offsetWidth / 2);
      y = (y / 2) + document.body.scrollTop - (element.offsetHeight / 2);
      if (arguments.length < 2) left = true;
      if (left) element.style.left = x + 'px';
      if (arguments.length < 3) top = true;
      if (top) element.style.top = y + 'px';
      }

      // method to determine the browser for browser-specific javascript.
      // Currently returns a string with possible values IE6, IE7, Firefox, Other
      function getBrowser()
      {
      if (navigator.appName == 'Microsoft Internet Explorer')
      {
      return 'IE' + parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]);
      }
      else if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1)
      {
      return 'Firefox';
      }

      return 'Other';
      

      }

      Cheers, Craig ** I'd rather try and fail than fail to try ;) **

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups