iframe automatically obtains onload height and width
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:
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?
Statement: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