Compatible with the mainstream browser iframe adaptive high js script

  • 2020-03-30 01:20:48
  • OfStack

Compatible with the mainstream browser Iframe adaptive height, js script as follows:
 
//The iframe is highly adaptive
function iframeAutoFit(iframeObj) { 
setTimeout(function () { 
if (!iframeObj) return; 
iframeObj.height = (iframeObj.Document ? iframeObj.Document.body.scrollHeight : iframeObj.contentDocument.body.offsetHeight); 
}, 200); 
}<span style="font-family: Arial, Helvetica, sans-serif;"> </span> 

Call method:
 
<iframe id="HQRight" name="HQRight" onload="javascript:iframeAutoFit(this);" 
height="235px;" width="770px" frameborder="0" scrolling="no" 
src="Market/HQData_page.aspx?t=tjs"></iframe> 

Extension:
 
//Dynamic add style
function addSheetFile(obj, path) { 
if (obj == undefined || obj == null) 
obj = document; 

var fileref = obj.createElement("link") 
fileref.rel = "stylesheet"; 
fileref.type = "text/css"; 
fileref.href = path; 
fileref.media = "screen"; 
var headobj = obj.getElementsByTagName('head')[0]; 
headobj.appendChild(fileref); 
} 

Related articles: