要兼容IE6,7,8的
iframe的结构,是
<iframe name="bbcode" id="bbcode" src="bbcode/bbcode.php" frameborder="0" marginheight="0" marginwidth="0" scrolling="No" style="width: 100%; height: 410px;"></iframe>然后BBCODE页面下<iframe id="contents" name="contents" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto"></iframe> 给contents 赋值

解决方案 »

  1.   

    window.frames["contents"].document.body.innerHTML="赋值"
      

  2.   


     'window.frames.contents.document' 为空或不是对象你这个不行的。
      

  3.   

    document.getElementById( "bbcode ").contentWindow.document.body.innerText=“”;
      

  4.   

    不好意思,写错了
    document.getElementById( "bbcode ").contentWindow.document.getElementById( "content").contentWindow.document.body.innerText="";
      

  5.   


    jieshao.php<?php include_once"ajax.php"; include_once"access_denied.php";?>
    <link href="admin.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="../include/js/admin.js"></script>
    <script type="text/javascript" src="../include/js/ajax.js"></script>
    <div id="admin_message">
    <div id="admin_message_1">
    <div id="admin_right_3_1">企业介绍 </div><br />
    <iframe name="bbcode" id="bbcode" src="bbcode/bbcode.php" frameborder="0" marginheight="0" marginwidth="0" scrolling="No" style="width: 100%; height: 410px;"></iframe>
    <input id="news" type="button" name="" onclick="jieshao_xx()" value="保存介绍" />
    </div>
    <?php
    $corp = $mz_mysql->mysql_give("select * from mzrui_corp");
    $str = str_replace("\n",  "",  $corp[corp]);
    $str = str_replace("\r",  "",  $str);
    echo ("<script>window.onload = function(){corp('$str');}</script>");
    ?>JSfunction corp(jieshao)
    {
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
    document.getElementById( "bbcode").contentDocument.getElementById( "contents").contentDocument.body.innerHTML = jieshao; }
    else
    {
    document.getElementById( "bbcode").contentWindow.document.getElementById( "contents").contentWindow.document.body.innerHTML = jieshao; }
    }然后BBCODE.PHP 就是这个 <iframe id="contents" name="contents" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto"></iframe>
      

  6.   


    你的这个方式只能在firefox下用,IE 8 下不行
      

  7.   

    document.frames( "bbcode ").document.frames( "content").document.body.innerText="";
      

  8.   

    会不会是window.onload  冲突我BBCODE 页面下的JS 也有个window.onload = function()
    {
    var f = window.frames["contents"];
    f.document.designMode="on";


    }
      

  9.   


    你的这个方式好像赋值也不行,不知道是不是页面装载没完成造成的,'document.frames(...).document.frames(...).document.body' 为空或不是对象报这个错误
      

  10.   

    跨域iframe里面的DOM好像不能读取和更改。
      

  11.   

    <iframe id="contents" name="contents" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto"></iframe>  
    <input type=button value="赋值" onclick="Add()" />
    <script>
    function Add()
    {
     window.frames["contents"].document.open();
     window.frames["contents"].document.write("<body>赋值</body>")
     window.frames["contents"].document.close();
    }
    </script>
      

  12.   

    'window.frames.contents.document' 为空或不是对象
    那是因为你的iframe是空的,没有document对象的,。你这样写
    <iframe src="b.htm" name="contents" b.htm写
    <html>
    <body>
    </body>
    </html>就可以了
      

  13.   

    楼主你说的对,就是你用了onload的问题,你在页面加载的时候去取框架Iframe里的内容,然而iframe加载bbcode/bbcode.php这个页面会有个延迟,然后执行顺序就变成这样了:
    onload执行---->iframe元素生成----->onload执行完---->iframe加载src中的页面
    结果就是你取不到Iframe中src指定页面的document对象
    我是新手,纯属个人理解,有不对的地方希望大神们纠正,楼主可参考
      

  14.   


    不过这个在FF下面没有问题的,就是在IE下面 会报对象为空
      

  15.   

    看看这个
    获取/设置IFRAME内对象元素的几种JS方法(2011
      

  16.   

    我也不解了,昨天我也是用FF测的,结果返回为NULL,然后给加个alert强制其执行顺序就好了,难道FF版本问题?其实这个类似的问题先前也遇到过,楼上大神应该有印象,也是ifame的加载问题。反正我总觉得这个跟iframe的加载延迟有关,如果src响应慢点即时FF也会出问题。个人理解,仅供参考
      

  17.   

    alert  不是弹窗口吗?能举个例子吗!怎么让他顺序执行?
      

  18.   

    你在js文件的第一行去设一个alert就可以了,这不是解决问题的办法
      

  19.   

    谁给个解决方案???怎么让内嵌的BBCODE.PHP 页面加载完后,在执行
    echo ("<script>window.onload = function(){corp('$str');}</script>");
      

  20.   

    内嵌的BBCODE.PHP?
    你把代码写这个页面里面,而不是外面