Home > Web Front-end > JS Tutorial > body text

javascript firefox automatically loads iframe and automatically adjusts height and width example_javascript skills

WBOY
Release: 2016-05-16 17:24:27
Original
836 people have browsed it

iframe automatically obtains onload height and width

Copy code The code is as follows:

function AutoResize(iframe)
{
//firefox
if(iframe.contentWindow)
{
iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;
iframe.width = iframe.contentWindow. document.documentElement.scrollWidth;

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

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

iframe auto-loading:
Copy code The code is as follows:

var tdObj = document.getElementById('ifrtd');
tdObj.innerHTML = 'QQ is loading dynamically... ';

var iframe = document.createElement("iframe");
iframe.src = 'http://www.zbphp.com/';

if (iframe.attachEvent){

//iframe.attachEvent("onload",AutoResize.call(iframe)); #Error reporting
iframe.attachEvent("onload", function(){
AutoResize(iframe);
});
} else {

//iframe.onload = AutoResize.call(iframe); #Error report is not supported
iframe.onload = function(){
AutoResize(iframe) ;
};
}

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

In fact, the iframe.onload here wants to be written as iframe.onload = AutoResize.call(iframe); Unfortunately, an error is reported and it is not supported.

I never knew how to make function calls in javascript. For example, when iframe.onload = function(){} calls a function and has parameters, you can only write it like this instead of passing parameters directly like other programs.

I have seen apply() call() before, but it is not supported even if I try it. Why?
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template