简体   繁体   中英

How to resize an IFRAME on load in an .aspx page?

In an .aspx page with a VB.NET codebehind I am using an IFRAME which would be created inside the repeater control.

Since I want to resize the IFRAME based on the content within the page I have been using the resize function obtained from here on the IFRAME onload as shown below.

<iframe id="IframeSubsectionArea" scrolling="auto" width="100%" onload="resizeIframeToFitContent(this)" runat="server">

However it is throwing an error as the method could not be found in the form.

  1. Is there any client side script variant for the onload event?
  2. What might be the reason for the error and its solution?

If you don't mind using jQuery the first answer on here should do the trick jQuery .ready in a dynamically inserted iframe

$(document).ready(function() {
   $("iframe").load(function() {
        var iframe = $(this);

        //Do your resize here via the iframe var
   });
 });

Failing that, you may be getting the error due to this block of code being missing from your document however as you have not posted the actual error i cannot be sure.

<SCRIPT LANGUAGE="JavaScript">
function resizeIframeToFitContent(iframe) {
    // This function resizes an IFrame object
    // to fit its content.
    // The IFrame tag must have a unique ID attribute.
    iframe.height = document.frames[iframe.id]
                    .document.body.scrollHeight;
}
</SCRIPT>

Edit: If that doesn't work post some example code, and the actual error you are getting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM