网页里面嵌入广告,是以<iframe id=add border=0 frameborder=0 marginheight=0 marginwidth=0 width=774 height=516 scrolling=no allowtransparency=true src=http://xxx.xxx.com/adshow.php?adzone=123456></iframe>
这样的形式嵌入到页面中的,但是广告服务器经常出问题,出问题的时候就显示不出广告,在我的页面上就是空白(774*516),从firebug里看到的代码是<html>.....<table...><tr><td></td></tr></table>....</html>,正常情况下<td></td>之间是有广告内容的,比如:<a href="..."><img....></a>。现在我想用js检测iframe所载入的内容的长度(字节数),当长度比较小,就认定广告没能载入,就转而调用另外一个广告商的广告代码。现在的问题是 我无法获得iframe所载入的内容的长度(字节数),特向高人请教。

解决方案 »

  1.   

    document.getElementById("add").contentWindow.document.body.outerHTML.length
      

  2.   

    window.frames["add"].contentWindow.document.documentElement.length
      

  3.   


    outerHTML不是W3C的标准属性,所以FF不支持,因此会报错。用document.getElementById("add").contentWindow.document可以找到frame页面的dom对象,但是具体怎么获取加载内容的长度,(不用outterHTML),不是很清楚。。
      

  4.   

    document.documentElement对象没有length这个属性