<iframe id=web></iframe>
<script>
function window.onload(){
web.document.designMode='on';web.document.open();web.document.clear();web.document.write("&nbsp;");
}
function document.onclick(){
temp1=web.document.images.length
web.focus();web.document.execCommand("InsertImage","abc","url")  //这个是弹出对话框的
if(temp1<web.document.images.length){  //如果插入之后比插入之前,多了一个图片对象则
alert(web.document.images[web.document.images.length-1].outerHTML)
}
}
</script>下面还有一个例子<iframe id=web></iframe>
<script>
function window.onload(){
web.document.designMode='on';web.document.open();web.document.clear();web.document.write("&nbsp;");
}
function document.onclick(){
web.focus();web.document.execCommand("InsertImage","","url")  //这个是不弹出对话框的
alert(web.document.images[web.document.images.length-1].outerHTML)  //不需要检索,直接得到最后一个图片对象
}
}
</script>

解决方案 »

  1.   

    var a=iframe.getElementsByTagName("img")
    for(var i=0,i<a.length;i++){
    alert(a[i].src)  //遍历iframe中的所有图片
    }
      

  2.   

    lshdic(风云舞):我的图片不一定在最后的,可能在最前插的
      

  3.   

    to shdic(风云舞):我觉得你的方法还得改进呀,一旦要是用户把图片插到中间怎门办,你取最后一个图片就不对了!
      

  4.   

    还有一个问题:请问如果取得当前页面得到焦点的对象呢?(javascript)
      

  5.   

    to  zhaoweiwei(if(轩辕剑^倚天剑)) :
    alert(a[i].src)  //遍历iframe中的所有图片  ,的作用是什么??
      

  6.   

    晕哦,没考虑这一点,用VAR也绑定不了,我也没折了..
      

  7.   

    var a=iframe.getElementsByTagName("img")//遍历iframe中的所有图片for(var i=0,i<a.length;i++){
       if(a[i].src=="你新插入的图片的连接")
       { 
          alert("这就是你新插入的图片")
    }                          }
      

  8.   

    有个思路或许可以(但不是绝对精确)在插入以前,将已存在IFRAME中的图片的OUTERHTML读进一个数组等插入以后,在循环这个数组及所有图片对象,总会有一个不同的,而循环到那个不同的时,BREAK;退出循环,得到引用只所有不精确是因为OUTERHTML,可能有重复.
      

  9.   

    或者:ifrmae.document.execCommand("InsertImage","","url")var a=iframe.getElementsByTagName("img")//遍历iframe中的所有图片for(var i=0,i<a.length;i++){
       if(a[i].src="url")
       { 
          a[i].focus();
          alert("这就是你新插入的图片")
    }                          }
      

  10.   

    倚天剑更加简单,不过采用"弹出对话框"让用户添写URL时是求不到这个SRC"你新插入的图片的连接"只有插入之前将所有图片OUTERHTML改成数组,在等插入以后将所有图片OUTERHTML在改成第二个数组,然后比较这两个数组,如果第二个数组有的,第一个数组里没有,那么多余的那个就是新插入的图片对象了