有个办法不知道你能否用:
直接指定iframe的src肯定是异步的;但是在iframe外边使用document.write方法直接将html代码写入iframe的document是同步的,所以基于这个原理:try
{
//在客户端创建xmlhttp对象
var oHttp = new ActiveXObject("Microsoft.XMLHTTP");
// open url
oHttp.Open("POST","your html url", false);
//发送请求
oHttp.send(oRequestXML.xml);
//得到html源码
var strRet = oHttp.responseText;
//得到iframe对象
var oFrame = document.frames("yourframeid");
//得到frame document对象
var oDoc = oframe.document;
//写入html
oDoc.open();
oDoc.write(strRet);
oDoc.close();
//继续你的处理
......
}
catch(e)
{
  //出错处理
 ......
}//note注意:
如果你所装载的html包含了类似 <script src="xxxx.js"></script>
这样的代码,不适用,建议你将这样的js都变成inline的js,
并且只适用于IE5.0以上!

解决方案 »

  1.   

    有点错误:
    oHttp.send(oRequestXML.xml)  ====> oHttp.send()
      

  2.   

    这种情况最好是用回调函数。看下面的callBack函数:a.html:<HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    </HEAD>
    <script>
    var t;
    function fnload(){
    ifrMain.document.URL = "b.html";
    }
    function callBack(){
    alert("b page is loaded ......")
    }
    </script>
    <BODY onload = "fnload()"><iframe id = "ifrMain" width = "500" height = "500"></iframe>
    </BODY>
    </HTML>b.html:
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    </HEAD>
    <script>
    alert("hello world");
    </script>
    <BODY onload="parent.callBack()">
    hello world
    </BODY>
    </HTML>要往下做的事情在callBack里面写。
      

  3.   

    xujun1974(牛牛) 
    你是徐俊吧,呵呵
    我知道,我们以前是使用这种方法,但是现在是不仅要写一般的HTML代码,还要写一些JS脚本在里面,这样就比较麻烦了
      

  4.   

    emu(ston) :
    &raquo;&Oslash;&micro;÷&ordm;&macr;&Ecirc;&yacute;&Ograve;&sup2;&sup2;&raquo;&ETH;&ETH;°&iexcl;&pound;&not;&iquest;&acute;&Icirc;&Ograve;&micro;&Auml;&Ecirc;&Ocirc;&Ntilde;é&pound;&ordm;
    a.html:
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    </HEAD>
    <script>
    var t;
    function fnload(){
    ifrMain.document.URL = "b.html";
    alert("main page")
    }
    function callBack(){
    alert("b page is loaded ......")
    }
    </script>
    <BODY onload = "fnload()"><iframe id = "ifrMain" width = "500" height = "500"></iframe>
    </BODY>
    </HTML>b.html:
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    </HEAD>
    <script>
    //alert("hello world");
    function fnload()
    {
    alert("child page")
    ddd.style.fontSize = 20;
    ddd.style.color = "red";
    parent.callBack()
    }
    </script>
    <BODY onload="fnload()">
    <div id = "ddd">hello world</div>
    </BODY>
    </HTML>&Icirc;&Ograve;&Ograve;&ordf;&micro;&Auml;&ETH;§&sup1;&ucirc;&Ecirc;&Ccedil;&Iuml;&Egrave;&micro;&macr;&sup3;&ouml;"child page"&Ocirc;&Ugrave;&micro;&macr;&sup3;&ouml;"b page is loaded ......"&pound;&not;×&icirc;&ordm;ó&micro;&macr;&sup3;&ouml;"main page"
    &para;&oslash;&Ecirc;&micro;&frac14;&Ecirc;&frac12;á&sup1;&ucirc;&Egrave;&acute;&Ecirc;&Ccedil;"main page"-> "child page"->"b page is loaded ......"
      

  5.   

    emu(ston) :
    回调函数也不行啊,我的试验如下:
    a.html:
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    </HEAD>
    <script>
    var t;
    function fnload(){
    ifrMain.document.URL = "b.html";
    alert("main page")
    }
    function callBack(){
    alert("b page is loaded ......")
    }
    </script>
    <BODY onload = "fnload()"><iframe id = "ifrMain" width = "500" height = "500"></iframe>
    </BODY>
    </HTML>b.html:
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    </HEAD>
    <script>
    //alert("hello world");
    function fnload()
    {
    alert("child page")
    ddd.style.fontSize = 20;
    ddd.style.color = "red";
    parent.callBack()
    }
    </script>
    <BODY onload="fnload()">
    <div id = "ddd">hello world</div>
    </BODY>
    </HTML>我需要的效果是先弹出"child page",然后是"b page is loaded ......",最后是"main page"
    而实际结果是"main page"-> "child page"->"b page is loaded ......"