SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru davedibiase's Avatar
    Join Date
    Aug 2001
    Location
    Toronto, Canada
    Posts
    829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Finding resolution of user with JS?

    How would I be able to find the users screen resolution so that I may use it within my PHP script?

    Thanks!
    ||Dave Di Biase||
    ----------------------------------
    "There are 2 secrets in life. 1) Never say everything you know."
    GFXWARS - The ultimate graphics battle!

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2002
    Location
    Ireland
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    To find the user's screen resolution you have to use a client side piece of code, however it should be easy to get the resolution in js and then use it in php, by passing it as a parameter to a php page or loading a different php page depending on the user's resolution

    For code, check this link

    http://www.zimmertech.com/tutorials_resdetect.html

    - Sean

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Don't think that just because they have a certain resolution that they'll be browsing your site fullscreen! My resolution at work is 1600x1200; at home it's 1280x960, but very rarely do I browse fullscreen. My typical window size is actually around 800x600, so I can see multiple windows at the same time.

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So how does one detect the dimensions of the browser (client) window? And more importantly the viewable area in the browser window?

    Regards, Ben
    Experience is that thing which lets you know you've made the same mistake yet again.

  5. #5
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Code:
    window.innerWidth;
    window.innerHeight;
    ??

  6. #6
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by vgarcia
    Code:
    window.innerWidth;
    window.innerHeight;
    ??
    Support for window.innerWidth and window.innerHeight isn't widespread yet.

    As a Mac user I can't vouch for IE6, but IE5 (at least) uses:
    Code:
    document.body.clientWidth;
    document.body.clientHeight;
    Code:
    if (document.getElementById && document.all) {
    var winW = document.body.clientWidth;
    var winH = document.body.clientHeight;
    } else {
    var winW = window.innerWidth;
    var winH = window.innerHeight;
    }
    
    // do something that uses winW;
    // do something that uses winH;
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  7. #7
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Nice catch Bill, as I wasn't really sure about them. Thanks!


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
  •