SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Set the Div element to fill the whole screen?

    Suppose I have the following script that creates a div element and set its width and height to fill the whole screen:

    Code:
    <script type="text/javascript">
    	var oDiv = document.createElement('div');
    	oDiv.style.width = window.screen.availWidth + "px";
    	oDiv.style.height = window.screen.availHeight + "px";
    	//oDiv.style.width = window.screen.width + "px";
    	//oDiv.style.height = window.screen.height + "px";
    	oDiv.style.border = "solid 1px #ccc";
    	document.body.appendChild(oDiv );
    </script>
    well, the code above actually does the job, BUT a scrollbar (vertical and horizontal) is also created ... how to get rid of the scrollbars?

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    You're setting the div to be the size of the user's screen, not the size of the browser window. This will anger people who don't keep their browser windows maximized. Don't use screen.width/screen.height, use window.innerWidth and window.innerHeight or some other method instead.

  3. #3
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia View Post
    ... use window.innerWidth and window.innerHeight or some other method instead.
    ok ... and how do I use it so it works also in IE ? not just in mozilla !

    I also tried this:

    oModalBackground.style.width = document.documentElement.clientWidth + "px";
    oModalBackground.style.height = document.documentElement.clientHeight + "px";

    but still the scrollbars are alive!

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi KenA, Welcome to SPF

    For reference:

    xClientWidth

    xClientHeight


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •