Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6808789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:59:56+00:00 2026-05-26T19:59:56+00:00

I’m dynamically resizing my UIWebView depending on the content in it. If there is

  • 0

I’m dynamically resizing my UIWebView depending on the content in it. If there is alot of content it might span the height of the UIWebView to 1000px and if content is less it might span to 500px (so the UIWebView will have any arbitrary heigh from 0-n px). The code I’m using to find out the UIWebView height after it has loaded the document is this:

- (void)webViewDidFinishLoad:(UIWebView *)webView {

    // Change the height dynamically of the UIWebView to match the html content
    CGRect webViewFrame = webView.frame;
    webViewFrame.size.height = 1;
    webView.frame = webViewFrame;
    CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
    webViewFrame.size = fittingSize;
    webViewFrame.size.width = 276; // Making sure that the webView doesn't get wider than 276 px
    webView.frame = webViewFrame;

    float webViewHeight = webView.frame.size.height;
}

This works perfectly. But to add to the complexity I’m using javascript (jquery) to check if there is an image in the document that is wider than 276 pixels (the width of my UIWebView).

IF there is an image that is wider I add a class to the img tag named “oversized” and have a css rule that will scale the image properly so it will not be wider than 276 pixels. Since the javascript runs after the document has finished loading I can not longer “catch” the UIWebView height. How can I get the new document height after the javascript has been run?

The javascript I’m using looks like this:

<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.2.js'></script>                            
<script type='text/javascript'>
<![CDATA[  
$(window).load(function(){
    $(document).ready(function() { 
        $('img').each(function(e) { 
            if ($(this).width() > 276) { 
                $(this).parent().addClass('oversized');
            } 
         }); 
    }); 
}); 
//]]>
</script>

And the CSS:

.oversized * { 
    border: 2px solid red;
    width: 100%;
    height: auto;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:59:56+00:00Added an answer on May 26, 2026 at 7:59 pm

    In your -webViewDidFinishLoad: method, you might try adding

    NSString *height = [webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"];
    

    Also, instead of using jQuery to try and find the oversized images – in your css, just change the ‘width: 100%’ to ‘max-width: 100%’ and set it for all images:

    img { 
        border: 2px solid red;
        max-width: 100%;
        height: auto;
        -webkit-box-sizing: border-box;
    }
    

    The box-sizing rule will make sure the borders don’t add extra pixels to the width.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.