SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2007
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jquery width() and height() returning incorrect values in IE

    jquery width() and height() functions are consistently returning the wrong values for the viewport size (i.e. $(window).width). Anyone know why..or what I can do to fix it?

    thanks.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Seems IE has a different way of calculating the viewport width and height, i would simply do the following so IE in IE the correct width is still set

    Code JavaScript:
    var viewPortWidth;
    var viewPortHeight;
     
    $.each($.browser, function(i){
        if ($.browser.msie){
            viewPortWidth = $.width()+4;
            viewPortHeight = $.height()+2;
        } else {
            viewPortWidth = $.width();
            viewPortHeight = $.height();
        }
    });

    That's just how i would do it but someone else might have something better

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,891
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    No need for $.each

    Code JavaScript:
    var viewPortWidth;
    var viewPortHeight;
     
    if ($.browser.msie){
      viewPortWidth = $.width()+4;
      viewPortHeight = $.height()+2;
    } else {
      viewPortWidth = $.width();
      viewPortHeight = $.height();
    }
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2007
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works perfectly. Thanks guys.


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
  •