解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
     <title>Torap betin jobalaw kwrsi</title>
     <meta http-equiv="Content-Type" content="text/html;charset=utf-8;" />
     <meta name="keywords" content="" />
     <meta name="description" content="" />
     <meta name="author" content="" />
    </head>
    <body  onload="setEditor()">
        <iframe id="ifr" src="about:blank" width="25%" height="25%"></iframe>
    <script type="text/javascript">
        function setEditor() {
            var doc = document.getElementById('ifr').contentWindow.document;
            doc.designMode = 'on'
            function keyPress(e) { alert(e.keyCode) }
            if (doc.addEventListener) { doc.addEventListener('keyup', keyPress, false); }
            else doc.attachEvent('onkeypress', keyPress);
        }
    </script>
    </body>
      

  2.   

    IE8-没问题,IE9+没有测试,不行先判断attachEvent先        if (doc.attachEvent) doc.attachEvent('onkeypress', keyPress);
            else doc.addEventListener('keyup', keyPress, false); 
      

  3.   

    楼主,说实话,不建议用iframe,内存泄露,浏览器兼容问题也多,交互的子父页面也麻烦。
    用div来实现多好,用个jquery 或 dojo实现蒙层