Frame page height automatically refreshes Javascript script

  • 2020-03-26 21:46:00
  • OfStack

Realization principle: When loading index.htm, the script is automatically called to refresh the code of the frame page every 1 second
Code advantages: You just need to set up the script in the index.html framework page, and you don't need to set up any code in the child page that the call loads.
The code of index.htm is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> 
<html xmlns=""> 
<title> Home page </title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<div style="float: left; width: 740px; height:auto; border: 1px #808080 Solid; margin: 5px 0px 5px 10px;overflow: hide"> 
<iframe name="ifr_obj" id="ifr_obj" src=" Other page addresses or file names are nested here " frameborder="0" width="100%" scrolling="no" title=" Framework page "></iframe> 
<script language="javascript" type="text/javascript"> 
function initIframeHeight() { 
try { 
var iframe = document.getElementById("ifr_obj"); 
if (iframe != null) { 
if (iframe.contentWindow.document.body != null) { 
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) { 
alert(" Error loading frame page height "+ex.toString()); 
window.setInterval("initIframeHeight()", 1000); 

Related articles: