Home > Article > Web Front-end > Example of javascript firefox automatically loading iframe and automatically adjusting height and width
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!