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 198415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:56:08+00:00 2026-05-11T16:56:08+00:00

I have a C# webbrowser that holds an html page that has several iframes.

  • 0

I have a C# webbrowser that holds an html page that has several iframes. Each iframe holds an arbitrary html file, often with images. The img tags often don’t have any width or height attributes (ie, it’s often just <img src="someimage.jpg">).

I’ve read about how to size iframes based on their content, and have gotten it to work using jquery. The following jquery snippet is present in the iframe’s html:

$(document).ready(function() {
  $('img').each(function(){ 
        $(this) 
            .bind('load readystatechange', function(e) {
                var iframes = window.top.document.getElementsByName(window.name);
                if (iframes.length == 1) {
                    window.top.DoResizeFrame(iframes[0]);
                }
            })
    }); 

DoResizeFrame is defined in the parent html file (the one that the webbrowser is showing):

 function DoResizeFrame(fr) {
        if (fr && fr.Document && fr.Document.body) {
            fr.style.height = fr.Document.body.scrollHeight + 'px'; 
            fr.style.width = fr.Document.body.scrollWidth + 'px';
        }
    }

I also call DoResizeFrame from the parent document’s $(document).ready event. This works great – if there are no images, the document’s ready event triggers a resize. If there are images, each time an image is finished loading, the iframe is properly resized.

However, loading a large image causes the iframe to be improperly sized until the image is completely loaded. Since I rarely have the width and height attributes in the image tag to work with, I figured I could use jquery to listen to the readystatechange event of the image, and when it’s “loading”, pick up the size of the image and properly size the iframe even while the image is still loading. Unfortunately, at least in IE7, readystatechange=loading only happens after the image is done being downloaded.

Does anyone have any ideas how I can detect the size of an image referenced in my html simply by “<img src="someimage.jpg">” without waiting for the entire download to happen? I’m trying to provide the best user experience by sizing everything correctly, so that the user can read the rest of the iframe even if a large image is taking a while to download.

thanks!
jean

  • 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-11T16:56:08+00:00Added an answer on May 11, 2026 at 4:56 pm

    One dependable way to be sure is to ask the server the size of the image before downloading it. I’ve done this using .net, it’s quite easy.

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

Sidebar

Related Questions

I have a HTML page that I want to display in a WebBrowser control,
I have a C# WinForms application that has a WebBrowser control inside of it.
We have a windows application that contains an ActiveX WebBrowser control. As part of
I have an .Net Froms application that displays web pages through a WebBrowser control.
Here's the issue: I have a hook in IE that reacts on WebBrowser.OnNavigateComplete2 event
I have a webbrowser object on a winform that I would like to use
Using Silver 4, I have a webbrowser control that I set to a web
I have a webbrowser control which I navigate to an URL that contains this
Say that I have a table with two rows, and a cell in each.
I have a Windows Forms application in C#/Visual Studio 2008 with an IE WebBrowser

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.