怎么样把左边框架中的源代码完整赋值给右边框架的一个文本框?
这个,用document.body.innerHTML
会丢失值的..
并且一些body之外的函数也不可以...如果非要这样的话就用XMLHTTP||XMLHTTPRequest

解决方案 »

  1.   

    编码和跨域
    xmlhttprequest可以实现
      

  2.   

    framest
    还涉及跨域?
    O_O
      

  3.   

    除去之外的,document.body.outerHTML不会丢失值吧
      

  4.   

    IE6,Firefox2下测试通过,手边没有Opera,未测试
    -------------------
    default.htm
    <script language="javascript">
    function cloneCode(){
    frm2.document.getElementById("txt").value = (typeof(HTMLElement) != "undefined"?
    frm1.document.createElement("DIV").appendChild(frm1.document.documentElement.cloneNode(true)).parentNode.innerHTML
    :
    frm1.document.documentElement.outerHTML
    )
    }
    </script><div><input type="button" value="LeftFrame's code To RightFrame's TextArea" onclick="cloneCode()" /></div>
    <div style="float:left">
    <iframe id="frm1" name="frm1" style="width:400px;height:400px" src="left.htm"></iframe>
    </div>
    <div style="float:left">
    <iframe id="frm2" name="frm2" style="width:400px;height:400px" src="right.htm"></iframe>
    </div>left.htm
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <title>网页标题</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <script language="javascript">
    function hello(){
    alert('Hello!');
    }
    </script>
    </head>
    <body>
    LeftFrame
    </body>
    </html>right.htm
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <title>网页标题</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    RightFrame<br /><br />
    <textarea id="txt" name="txt" style="width:360px;height:300px">code...</textarea>
    </body>
    </html>
      

  5.   

    假如
    <iframe id="frm1" name="frm1" style="width:400px;height:400px" src="left.htm"></iframe>
    这里指向的不是left.htm,而是一个其他网站的页面呢?
      

  6.   

    xuStanly 
    依依MyLove 
    等 级:
     发表于:2008-01-09 23:30:467楼 得分:0 
    假如 
    <iframe   id="frm1"   name="frm1"   style="width:400px;height:400px"   src="left.htm"> </iframe> 
    这里指向的不是left.htm,而是一个其他网站的页面呢? 
     
    这样是不行的,你可以通过服务端XMLHTTP先获取目标页,然后才好操作!
      

  7.   

    如果有跨域的情况,那只能用XMLHttpRequest了。至于兼容IE和FF,可以参考prototypePS:好像楼主没提有跨域的情况
      

  8.   

    parent.frames["right"].document.getElementById("Text1").value = parent.frames[left].toString()
    你可以试试
      

  9.   

    parent.frames["right"].document.getElementById("Text1").value = parent.frames["right"].document.documentElement.outerHTML上面的错了,刚才试了一下,这样可以
      

  10.   

    我使用XMLHTTP解决了把左边的代码“完整”(完整,比较重要),outerHTML 的不完整。
    但是所有的文件编码都设置为gb2312的时候,返回值都是乱码。
    在FF加上
    XMLHttpRequest.overrideMimeType("text/html;charset=gb2312");
    可以解决
    在IE里还是无法解决。说明,我没有使用到服务器,就是几个html文件的本地执行。
      

  11.   

    XMLHttpRequest用这个东西要注意编码的转换  会出现乱码
    Function BytesToBstr(body)
    dim objstream
    set objstream = Server.CreateObject("adodb.stream")
    objstream.Type = 1
    objstream.Mode =3
    objstream.Open
    objstream.Write body
    objstream.Position = 0
    objstream.Type = 2
    objstream.Charset = "GB2312" 
    '转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP调用有中文字符的网页得到的将是乱码
    BytesToBstr = objstream.ReadText 
    objstream.Close
    set objstream = nothing
    End Function
      

  12.   

    楼上的兄弟,不行啊。错误:缺少对象‘server’
      

  13.   

    16楼是服务器端的vbs读文件的.放js里肯定出错了建议楼主把你的代码帖出来,别人好帮你解决
      

  14.   

    我的需求就是6楼的东西。<script language="javascript">
    function cloneCode(){
        frm2.document.getElementById("txt").value = (typeof(HTMLElement) != "undefined"?
            frm1.document.createElement("DIV").appendChild(frm1.document.documentElement.cloneNode(true)).parentNode.innerHTML
            :
            frm1.document.documentElement.outerHTML
        )
    }
    </script>只是这个代码不符合要求。
    frm1.document.documentElement.outerHTML
    返回的代码是不完整的。所以采用XMLHttpRequest解决了要求,但是在IE中显示为乱码,查了一些乱码的处理办法,还是没有解决。
      

  15.   

    6楼的代码在
    ie6.0,ff2.0,opera8.54都可以运行.
      

  16.   

    outerHTML是会自动格式化内容,又或者把16楼的改成客户端的JS代码应该也行,但有个安全设置提示,其实XMLHTTP是最好的选择了,编码是比较麻烦的问题,以前也因为这原因后来把页面全部编码改成统一。