一般 点网页任何地方都弹出a
我的写法如下 document.onclick = function(){alert('a')};
但是在iframe中如何达到这个效果了
下面的代码ff无效,也没想到该如何修改!~~~~~~~~~
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<head>
<script>
var ed = null;
var cd = null;
window.onload = function() {
    var o = document.getElementById("ss"); 
    ed = document.all?o.contentWindow.document:o.contentDocument;
    ed.open();
    ed.write('<html><head><style>html,body{margin:5px;font:14px;word-wrap:break-word}</style></head><body id="my_body"></body></html>');
    ed.close();
    ed.contentEditable = true;
    ed.designMode = 'on';
//////////////////////////////////////////////////////
    ed.onclick=function(){alert('a')}
};</script>
</head>
<BODY>
<IFRAME id="ss" height="200" src="about:blank" width="200" ></IFRAME>
</BODY></HTML>

解决方案 »

  1.   

    var fw=o.contentWindow;
    var fd=fw.document
    if(fw.attachEvent){
    fw.attachEvent("onclick",function(){alert('a')});
    }else{
    fw.addEventListener("click",function(){alert('a')},true); }
      

  2.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <HTML>
    <head>
    <script>
    var ed = null;
    var cd = null;
    window.onload = function() {
        var o = document.getElementById("ss"); 
        ed = document.all?o.contentWindow.document:o.contentDocument;
        ed.open();
        ed.write('<html><head><style>html,body{margin:5px;font:14px;word-wrap:break-word}</style></head><body id="my_body"></body></html>');
        ed.close();
        ed.contentEditable = true;
        ed.designMode = 'on';
        if(document.all)ed.onclick=function(){alert('a')}
        else ed.addEventListener("click",function(e){alert('a')},false)
    };</script>
    </head>
    <BODY>
    <IFRAME id="ss" height="200" src="about:blank" width="200" ></IFRAME>
    </BODY></HTML>