页面的iframe高度自适应

function reinitIframe(){
	var iframes = document.getElementsByTagName("iframe");
	for(var i = 0 ; i < iframes.length ; i++){
		var iframe = iframes[i];
		try{
			var bHeight = iframe.contentWindow.document.body.scrollHeight;
			var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
			var height = Math.max(bHeight, dHeight);
			iframe.height =  height;
		}catch (ex){}
	}
	
}
window.setInterval("reinitIframe()", 500);

 

你可能感兴趣的:(iframe)