Home  >  Article  >  Web Front-end  >  Example of javascript firefox automatically loading iframe and automatically adjusting height and width

Example of javascript firefox automatically loading iframe and automatically adjusting height and width

高洛峰
高洛峰Original
2017-01-12 11:19:441752browse

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 automatically loads:

var tdObj = document.getElementById('ifrtd'); 
tdObj.innerHTML = ' QQ动态加载中 ... '; 

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

if (iframe.attachEvent){ 

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

//iframe.onload = AutoResize.call(iframe);#报错不支持 
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 ,not support.

I have never known 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 after I tried it. Why?

For more javascript firefox automatic loading iframe automatic adjustment height and width examples related articles, please pay attention to the PHP Chinese website!

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