你好,感谢你阅读此帖...我写的一个Javascript代码块在调试的时候,发现这句:
 var oFrm = document.getElementById('infoA');提示变量oFrm 为Null或不是对象...我百思不得其解,,希望各位朋友帮我找找是什么原因...'infoA'是一个Iframe的ID..完整代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>无标题页</title>
<script type="text/javascript" language="javascript"> 
//    if(document.getElementById('infoA').document.readyState!="complete")
//        window.setTimeout('myrefresh()',10); 
    var oFrm = document.getElementById('infoA');
    oFrm.onreadystatechange = function() {
    if (this.readyState != 'complete') 
    {
    window.setTimeout('myrefresh()',2000); 
    }
    }
    function myrefresh()
  {
        //document.getElementById("infoA").src ='Default3.aspx';
        infoA.window.location.reload();
        //window.location.reload();
        
  }
    function Reflash()
    {
        window.setTimeout('myrefresh()',5000); 
    } 
    </script>
</head>
<body>
   <!-- <img src="Default3.aspx" id="img2" onload="Reflash()" /> -->
    
    <table  style="width:90%;height:600;" border="1" cellspacing="0" cellpadding="0">
    <tr>
      <td valign="top" style="width: 100%;">
<!-- 此处显示摄像头所属于宿舍或者(大门/围墙)的概况信息 -->
<iframe id="infoA" name="myFrame" enableviewstate="true" src="Default3.aspx" frameborder="0" scrolling="no" style="width:100%; height: 323px;" onload="Reflash()" >
</iframe>
</td>
      </tr>
  </table>    
</body>
</html>

解决方案 »

  1.   

    <script type="text/javascript" language="javascript"> 
    //    if(document.getElementById('infoA').document.readyState!="complete")
    //        window.setTimeout('myrefresh()',10); 
        var oFrm = document.getElementById('infoA');
        oFrm.onreadystatechange = function() {
            if (this.readyState != 'complete') 
            {
                window.setTimeout('myrefresh()',2000); 
            }
        }
        function myrefresh()
      {
            //document.getElementById("infoA").src ='Default3.aspx';
            infoA.window.location.reload();
            //window.location.reload();
            
      }
        function Reflash()
        {
            window.setTimeout('myrefresh()',5000); 
        } 
        </script>把这些代码单独贴出来醒目一点,嘿嘿
      

  2.   

    执行这句的时候,Body还没呈现啊,iFrame当然不存在啦
      

  3.   

    明白2楼的意思,那应该怎么做才能使用Iframe呢.
      

  4.   

    把所有的script放在iframe之后应该不会有这个问题了。
      

  5.   

    这样可以捕捉到Iframe了,我的目的是如果Iframe在一定时间内没有加载完,则重新加载,,
    请问我这样的代码可以实现吗?或者提供一下你的代码,谢谢,
      

  6.   

    朋友,换个思路也许更容易解决你的问题。
    实现方法如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>无标题页</title>
        <script type="text/javascript" language="javascript">
        var flagTag;
        //判断是否加载完成
        function judgeLoad() {
            //alert(flagTag);
            if (flagTag != 'ok') {
                window.setTimeout('myrefresh()', 2000);
            }
        }
        
        function myrefresh() {
            //document.getElementById("infoA").src ='Default3.aspx';
            infoA.window.location.reload();
            //window.location.reload();
        }
        function Reflash() {
            window.setTimeout('myrefresh()', 5000);
        }    function CallBack(Flag) {
            //alert("页面加载完成!" + Flag);
            flagTag = Flag;
            return Flag;
        }
        
    </script>
    </head>
    <body onload="judgeLoad();">
        <!-- <img src="Default3.aspx" id="img2" onload="Reflash()" /> -->
        <table style="width: 90%; height: 600;" border="1" cellspacing="0" cellpadding="0">
            <tr>
                <td valign="top" style="width: 100%;">
                    <!-- 此处显示摄像头所属于宿舍或者(大门/围墙)的概况信息 -->
                    <iframe id="infoA" name="myFrame" enableviewstate="true" src="Default3.aspx" frameborder="0"
                        scrolling="no" style="width: 100%; height: 500px;"></iframe>
                </td>
            </tr>
        </table>
    </body>
    </html>Default3.aspx页面中调用父页面的方法:
    <body onload="parent.CallBack('ok');">
      

  7.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>无标题页</title>
    <script type="text/javascript">
    // flag which indicates the loading progress
    var complete = false;
    </script>
    </head>
    <body>
    <table style="width: 90%; height: 600;" border="1" cellspacing="0"
    cellpadding="0">
    <tr>
    <td valign="top" style="width: 100%;"><!-- 此处显示摄像头所属于宿舍或者(大门/围墙)的概况信息 -->
    <iframe id="infoA" name="myFrame" enableviewstate="true"
    src="Default3.aspx" frameborder="0" scrolling="no"
    style="width: 100%; height: 323px;" onload="complete=true;"><!-- set flag to true after loading finished. -->
    </iframe>
    </td>
    </tr>
    </table>
    <script type="text/javascript" language="javascript">
    // check timeout 
    window.setTimeout(refresh, 5000);
    function refresh()
    {
    if (!complete) {
    alert("timeout, refresh iframe.");
    var infoA = document.getElementById("infoA");
    infoA.contentWindow.location.reload();
    // restart
    complete = false;
    window.setTimeout(refresh, 5000); 
    }

    </script>
    </body>
    </html>注意,如果iframe里的页面不存在的话IE会加载错误页,然后错误地把错误页的onload事件触发出来,很烦人。FF则没有这个问题。
    要解决的话就只能在iframe里面的页面最后触发parent.window.complete=true;了
      

  8.   

    把你的代码处理一下,然后用
    window.onload=function(){
       //这里调用你的代码
    }