我有段代码是在IFRAME 中插入图片的在IE8 下用相对路径可以但是FIREFOX 6.0 却不认,在之前的5.0 都可以显示,前2天升到了6.0 var f = document.getElementById("contents").contentWindow;
var icon = document.createElement('img');
icon.src = "../../attach/"+imgname;  // 就是这个相对路径 var range = f.getSelection().getRangeAt(0);
range.deleteContents();
range.surroundContents(icon);
range.collapse(false);不知道有什么办法解决???

解决方案 »

  1.   

    var icon = new Image();
    icon.src = "../../attach/"+imgname; 这样试试
      

  2.   

    不行啊,还是报加载URL 失败
      

  3.   

    <!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>
      
      </head>
      <body>
       <div id="time"></div>
        <script>
      var img = new Image();
    var a = 'aa.jpg';
    img.src = "../../" + a
    img.width = 100;
    img.height = 100;
    document.getElementById('time').appendChild(img)
      </script>
      </body>
    </html>
    我更新好 这样测试也能显示range.surroundContents(icon);你这个方法是什么?
      

  4.   

    <img src="../../attach/gb(1).gif" _moz_resizing="true">我这用FIREBUG 图片地址是这样的。 提示URL 加载失败
      

  5.   

    你上面那个AA.JPG 是放在那个路径下面的,这刚测试你的代码,然后换成我的图片地址也提示加载失败
      

  6.   


    你用iframe了?你是想改父页面的img地址是吗?
      

  7.   

    我发现问题了,应该和我这个框架页面有关我之前的测试都是在 http://localhost/2011-4-30\admin   这个路径下的 postnews.php 页面<iframe name="bbcode" src="bbcode/bbcode.php" frameborder="0" marginheight="0" marginwidth="0" scrolling="No" style="width: 100%; height: 410px;"></iframe>用IFRAME 包含进了单独打开BBcode.php 就路径不对BBCODE.php的路径是 http://localhost/2011-4-30\admin\bbcode
    不过IFRAME 包含进来路径应该也不会有什么不同把???
      

  8.   


    我看了一下你一楼的代码 你是父页面修改子页面里的img标签src属性是吧?http://localhost/2011-4-30\admin\bbcode你这个地址斜杠是打错了  还是就是这样?我怎么看着别扭呢
      

  9.   

    就是在IFRAME的编辑器里面插入一张图片啊, BBCODE.php   这个是编辑器页面postnews.php 是调用了这个编辑器页面<iframe name="bbcode" src="bbcode/bbcode.php" frameborder="0" marginheight="0" marginwidth="0" scrolling="No" style="width: 100%; height: 410px;"></iframe>BBCODE.php<iframe id="contents" name="contents" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto"></iframe> 这个是编辑框 iframe
      

  10.   

    不过用起来也应该没什么关系的,一般后台都是会直接打开 postnews.php 的,只要这个页面能显示就可以了,但是现在就是这个路径到前台去了会不会有问题 前台不需要'../../' 这个路径 要是可以和IE一样直接转成 http://localhost/这样的就好了
      

  11.   

    这个还真不知道FF行不行,FF好像都是显示相对地址的。