www.webdeveloper.com
Results 1 to 7 of 7

Thread: screen.width

  1. #1
    Join Date
    Feb 2006
    Location
    Buckingham, UK. (the Town, not the Palace)
    Posts
    148

    screen.width

    Hi, folks,
    I'm trying to obtain screen. width, height, availWidth and availHeight,
    but my code is failing. What's wrong?
    I'm using external JS, thus:
    <html>
    <head>
    <title>Screen Data</title>
    </head>
    <body>
    <script type="text/javascript src="screendata.js> </script>
    </body>
    </html>
    And here is my JS:
    var sw = screen.width;
    var sh = screen.height;
    var aw = availWidth;
    var ah = availHeight;

    var swm = "Screen Width = ";
    var shm = "Screen Height = ";
    var awm = "Available Width = ";
    var ahm = "Available Height = ";

    document.write(swm + sw);
    document.write(shm + sh);
    document.write(awm + aw);
    document.write(ahm + ah);
    It's probably obvious, but I'm dim.
    (I should sign myself Dim Doyce.)

  2. #2
    Join Date
    Feb 2006
    Location
    Buckingham, UK. (the Town, not the Palace)
    Posts
    148
    HI,
    I've changed my code, slightly.
    And have now embedded the Script in Body.
    It's now working - after a fashion.
    It produced exactly the same results
    in five different browsers:
    IE, FF, Chrome, Opera and Safari.
    I could imagine the Available Widths might be the same,
    But I'd expect the Available Heights to be different.

    Anyone have any suggestions why?
    JJ
    <html>
    <head>
    <title>Get Screen Data</title>
    </head>
    <body onresize="self.location.reload()">
    <script type="text/javascript">
    var sw = screen.width;
    var sh = screen.height;
    var aw = screen.availWidth;
    var ah = screen.availHeight

    var swmsg = "Screen Width = ";
    var shmsg = "Screen Height = ";
    var awmsg = "Available Width = ";
    var ahmsg = "Available Height = ";

    document.writeln ( swmsg + sw + 'px <br /><br />' );
    document.writeln ( shmsg + sh + 'px <br /><br />' );
    document.writeln ( awmsg + aw + 'px <br /><br />' );
    document.writeln ( ahmsg + ah + 'px <br /><br />' );
    </script>
    </body>
    </html>

  3. #3
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    Definition and Usage

    The availHeight property returns the height of the user's screen, in pixels, minus interface features like the Windows Taskbar.
    http://www.w3schools.com/jsref/prop_...vailheight.asp
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  4. #4
    Join Date
    Feb 2006
    Location
    Buckingham, UK. (the Town, not the Palace)
    Posts
    148
    Hi Padonak,
    Am I not right,
    different browsers have differing header heights,
    so surely, the available Height should differ?
    JJ

  5. #5
    Join Date
    Aug 2006
    Posts
    1,909
    The point is the screen is the physical screen, not the browser. If you tried your code using a monitor of different resolution, it should report different numbers.

  6. #6
    Join Date
    Feb 2006
    Location
    Buckingham, UK. (the Town, not the Palace)
    Posts
    148
    Quote Originally Posted by tracknut View Post
    The point is the screen is the physical screen, not the browser. If you tried your code using a monitor of different resolution, it should report different numbers.
    Hi TrackNut,
    My name is 'Jim'. My little nephew used to call me 'Dim'.
    His parents said he had problems with 'J'.
    But maybe he had a point.

    Thanks, I am Dim,
    but is there a way of getting current browser-height
    while it's displaying on my screen?
    Thanks
    JJ

  7. #7
    Join Date
    Aug 2006
    Posts
    1,909
    No worries Dim... I mean Jim

    I'm no JS master, but here's a link to what appears to be your answer - http://stackoverflow.com/questions/3...browser-height

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles