Javascript firefox automatically loads iframe and automatically adjusts the height and width.

Source: Internet
Author: User

Iframe automatically obtains the onload height and width
Copy codeThe Code is as follows:
Function AutoResize (iframe)
{
// Firefox
If (iframe. contentWindow)
{
Iframe. height = iframe.content?document.doc umentElement. scrollHeight;
Iframe. width = iframe.content?document.doc umentElement. scrollWidth;

}
// IE
Else if (iframe. contentDocument ){

Iframe. height = iframe. contentDocument. width;
Iframe. width = iframe. contentDocument. height;
}
}

Iframe automatic loading:
Copy codeThe Code is as follows:
Var tdObj = document. getElementById ('ifrtd ');
TdObj. innerHTML = 'qq dynamic loading ...';

Var iframe = document. createElement ("iframe ");
Iframe. src = 'HTTP: // www.zbphp.com /';

If (iframe. attachEvent ){

// Iframe. attachEvent ("onload", AutoResize. call (iframe); # error
Iframe. attachEvent ("onload", function (){
AutoResize (iframe );
});
} Else {

// Iframe. onload = AutoResize. call (iframe); # the error message is not supported.
Iframe. onload = function (){
AutoResize (iframe );
};
}

TdObj. innerHTML = '';
TdObj. appendChild (iframe );

In fact, the iframe. onload here is intended to be written as iframe. onload = AutoResize. call (iframe); unfortunately, an error is returned, not supported.

I have never known how javascript calls functions. For example, when iframe. onload = function () {} calls a function and has parameters, such a case can only be written in this way, rather than directly passing parameters like other programs.

I have seen apply () call () before, but none of them are supported. Why?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.