<html>
<head>
<script>
function showTopUp(){

var upFrame = document.createElement("iframe");
upFrame.src = "http://www.baidu.com";
upFrame.width="770";
upFrame.height="300"
upFrame.scrolling="no";
upFrame.frameborder="0";
if(upFrame.attachEvent){
    upFrame.attachEvent("onload", function(){
        document.getElementById("2").innerHTML = "";
        document.getElementById("2").appendChild(upFrame);
    });
} else {
    upFrame.onload = function(){
document.getElementById("2").innerHTML = "";
        document.getElementById("2").appendChild(upFrame);
return;
    };
}
 document.getElementById("2").appendChild(upFrame);
}
</script>
</head>
<body>
<SPAN id="span2" onclick="show(2);"><a href="javascript:showTopUp()" hidefoucs>十大涨幅股</a></span>
<div id="2" >
      <center>加载中</center>
</div>
</body>
</html>IE测试正常,可是火狐那里为什么不断的刷新呢?
如果我把
document.getElementById("2").innerHTML = "";
document.getElementById("2").appendChild(upFrame);
改成alert(/ganyoo/);
又只弹一次呢?

解决方案 »

  1.   

    在iframe的onload事件里面调用父页面的方法行不?
      

  2.   

    现在改成这样了,效果能达到,但还是不明白为什么上面那方法不行
    <html>
    <head>
    <script>
    function showTopUp(){

    var upFrame = document.createElement("iframe");
    upFrame.src = "http://www.ganyoo.com";
    upFrame.width="770";
    upFrame.height="300"
    upFrame.scrolling="no";
    upFrame.frameborder="0";
    if(upFrame.attachEvent){
        upFrame.attachEvent("onload", function(){
            document.getElementById("2").innerHTML = "";
            document.getElementById("2").appendChild(upFrame);
        });
    } else {
        upFrame.onload = function(){
    document.getElementById("2").innerHTML = "<iframe scrolling=no height=300 width=770 src=http://www.ganyoo.com />";
           
        };
    }
     document.getElementById("2").appendChild(upFrame);
    }
    </script>
    </head>
    <body>
    <SPAN id="span2" onclick="show(2);"><a href="javascript:showTopUp()" hidefoucs>十大涨幅股</a></span>
    <div id="2" >
          <center>加载中</center>
    </div>
    </body>
    </html>
      

  3.   


    var upFrame = document.createElement("iframe");
    //upFrame.src = "http://www.ganyoo.com";
    upFrame.setAttribute("src", "http://www.ganyoo.com");这样可以不
      

  4.   

    iframe的onload事件造成死循环了,在第一次onload时清楚掉onload事件 upFrame.onload = function(){
                document.getElementById("2").innerHTML = "";
                document.getElementById("2").appendChild(upFrame);
                upFrame.onload=null;//==============
     };
      

  5.   


    帅,这样搞定了,来了个新问题
    有边框,所有的属性都设置了                upFrame.setAttribute("scrolling","no");
    upFrame.setAttribute("frameborder","no");
    upFrame.setAttribute("marginwidth","0");
    upFrame.setAttribute("framespacing","0");
    upFrame.setAttribute("marginheight","0");
    upFrame.setAttribute("border","0");
    先是用upFrame.border="0"这样设置的,最后还是有框框,但是如果我这样
    document.getElementById("2").innerHTML = "<iframe  frameborder=no  marginheight=0 marginwidth=0 scrolling=no  height=300 width=770 src=share/stock/showTopUp.php />";
    这样写就不会有,也就是说有的属性设置不成功,怎么解释呢?
      

  6.   

    upFrame.frameBorder="0";//要区分大小写