Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better cross-browser height detection #35

Open
in0ni opened this issue Sep 7, 2012 · 0 comments
Open

Better cross-browser height detection #35

in0ni opened this issue Sep 7, 2012 · 0 comments

Comments

@in0ni
Copy link

in0ni commented Sep 7, 2012

i am finding that the height of the child is not always detected properly by firefox. with this plugin using the body scrollHeight at times returns a wrong value -- finding this with version 15.0 of FF.

after my multiple test (before i started using this plugin -- which rocks!), i am finding its best to test for at least two different ways to get the height, and grab the largest value of both -- this way preventing content being cut off in many cases too short. i have found this works best for FF and IE.

not sure how to submit a patch, so here is the code:

instead of:

       var $body = $(iframe, window.top.document).contents().find('body');
       var newHeight = $body[0].scrollHeight + options.heightOffset;

i have this:

        var largestHeight;
        var newHeight;

        // different methods to get the height, browsers return differnt values
        var heights = {
          bodyScrollHeight: $(iframe, window.top.document).contents().find('body')[0].scrollHeight,
          htmlHeight: $("html", iframe.contentWindow.document).height()
        };

        // test different heights and return the largest
        for(var key in heights){
          if(typeof largestHeight == 'undefined'){
            largestHeight = heights[key];
          }else if(heights[key] > largestHeight){
            largestHeight = heights[key];
          }

          if(options.diagnostics){
            debug(key + ": " + heights[key]);
          }
        };

        newHeight = largestHeight + options.heightOffset;

this seems to solve inconsistencies with method to acquire height. i am not using the straight up dom height ( ...document).height() ) since it can return absurdly large numbers -- but getting the height of html & body seem to work rather well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant