document.getElementById("fShowPage").window.document.onmousedown = function(e){alert(e);}

解决方案 »

  1.   

    IE下用 window
    FF下用 contentWindow
      

  2.   

    <div><iframe id="ifInDiv" src="2.htm"></iframe></div>
    <script>
    window.onload=function(){
      if(document.all)document.frames['ifInDiv'].document.onmousedown=function(){
        MouseDown(document.frames['ifInDiv'].event);//注意获取的是iframe中的事件对象,直接event会是null
      }
      else document.getElementById("ifInDiv").contentWindow.document.onmousedown=function(e){
        MouseDown(e);
      }
    }function MouseDown(e)
    {
      alert(e);
    }
    </script>
      

  3.   

    <html>
    <script>
    function $(id){
    return( document.getElementById(id));
    }
    function a(event){
    alert( 1 );
    }
    window.onload = function(){
    var f = $("iframe1").contentWindow || $("iframe1").window;
    f.document.onclick=a;
    }
    </script>
    <body>
    <iframe id="iframe1" src="2-2.html"></iframe>
    </body>
    </html>
      

  4.   

    楼上几位兄弟的代码在src定死的时候是可以的,可是如果iframe.src是由js设置的话,代码就不执行了.这种情况大家有没有遇到?
      

  5.   

    HOHO,这个问题我前两天回答过。
    是由于页面装载未完成的原因。
    你看看那个帖子吧。http://topic.csdn.net/u/20081102/16/f83ea1b7-5f7f-40e6-947f-63d4fcd5af1a.html