那只能一个一个FRAME的控制了?

解决方案 »

  1.   

    把你的script做成字符串var strScript='你上边的那些代码'function SetWindow(obj)
    {
    var script=obj.document.creatElement(strScript)
    document.body.appendChild(script)
    for(var i=0;i<obj.frames.length)
    {
    SetWindow(obj.frames[i])
    }
    }SetWindow(top)
      

  2.   

    xxuu503, 我试了你的方法,但是不可以。
      

  3.   

    放到你的那个script块的最后边
    function SetWindow(obj)
    {
      if(obj.document.all){ //ie has to block in the key down 
        obj.document.onkeydown = onKeyPress; 
      } 
      else if (obj.document.layers || obj.document.getElementById){ //NS and mozilla have to block in the key press; 
        obj.document.onkeypress = onKeyPress; 
      } 
    for(var i=0;i<obj.frames.length)
    {
    SetWindow(obj.frames[i])
    }
    }SetWindow(top)
      

  4.   

    xxuu503(我爱郭芙蓉!) ,我又试了你的方法,但还是不可以。 我给你发消息了。谢谢。
      

  5.   

    我修改了一下原来的代码。它现在还不能实现我说的功能,请大家帮忙 看看有什么错误没有,谢谢
    <script language=javascript> 
      var asciiF5 = 116;
      var asciiF6 = 117;
     
     for(i = 0; i < obj.frames.length; i++) 
      {
          frames[i].document.onkeydown=
          onKeyPress(evt)
          { 
            var oEvent = (frames[i].event) ? frames[i].event : evt; 
            var nKeyCode = oEvent.keyCode ? oEvent.keyCode :oEvent.which ? oEvent.which : void 0; 
            var bIsFunctionKey = false; 
            if(oEvent.keyCode==asciiF5 ||oEvent.keyCode==asciiF6)
            { 
                bIsFunctionKey = oEvent.keyCode; 
            } 
            var sChar = String.fromCharCode(nKeyCode).toUpperCase(); 
            var oTarget = (oEvent.target) ? oEvent.target : oEvent.srcElement; 
            var sTag = oTarget.tagName.toLowerCase(); 
            var sTagType = oTarget.getAttribute("type"); 
            var bRet = true;
            if(sTagType != null)
            { 
                sTagType = sTagType.toLowerCase(); 
            } 
             if(bIsFunctionKey)
            { 
                bRet = false; 
            } 
            if(!bRet)
            { 
               try
               { 
                 oEvent.returnValue = false; 
                 oEvent.cancelBubble = true; 
                 if(document.all)
                 { 
                    oEvent.keyCode = 0; 
                  }
                 else
                 { 
                    oEvent.preventDefault(); 
                    oEvent.stopPropagation(); 
                 } 
                }
               catch(ex)
               { 
       
               } 
            } 
            return bRet; 
      }
    </script>
      

  6.   

    你还是做成JS文件引用吧<script src="xxx.js"></script>
      

  7.   


      var asciiF5 = 116;
      var asciiF6 = 117;
     
    document.onkeydown=key;
    document.onkeypress = key;function key(evt)

            var oEvent = window.event || evt;
            var nKeyCode = oEvent.keyCode || oEvent.which;
            var bIsFunctionKey = false; 
            if(oEvent.keyCode==asciiF5 ||oEvent.keyCode==asciiF6)
            { 
                bIsFunctionKey = oEvent.keyCode; 
            } 
            var sChar = String.fromCharCode(nKeyCode).toUpperCase(); 
            var oTarget = (oEvent.target) ? oEvent.target : oEvent.srcElement; 
            var sTag = oTarget.tagName.toLowerCase(); 
            var sTagType = oTarget.getAttribute("type"); 
            var bRet = true;
            if(sTagType != null)
            { 
                sTagType = sTagType.toLowerCase(); 
            } 
             if(bIsFunctionKey)
            { 
                bRet = false; 
            } 
            if(!bRet)
            { 
               try
               { 
                 oEvent.returnValue = false; 
                 oEvent.cancelBubble = true; 
                 if(document.all)
                 { 
                    oEvent.keyCode = 0; 
                  }
                 else
                 { 
                    oEvent.preventDefault(); 
                    oEvent.stopPropagation(); 
                 } 
                }
               catch(ex)
               { 
       
               } 
            } 
            return bRet; 
    }你这单独的代码,可以把F5屏蔽掉,但是你在绑定到FRAME上时,你应该考虑两个问题,
    一,有可能会没有权限,这个很有可能,至少,FRAME的onload事件就不许外来的WINDOW上的脚本来绑定或重写
    二,考虑到该文档有没有载入,如果文档还未完全载入,你的脚本就完成了,那么根本就没有document对象的存在建议还是用JS文件引用的方式,因为有些地方,确实会可能存在载入的先后的事
      

  8.   

    在FRAMESET页面上屏蔽,并且让它KEYFIRST或者KEYPREVIEW(记不太清了),是不是可以呢?
      

  9.   

    KEYFIRST或者KEYPREVIEW是让页面优于页面中的其它控件而首先截获键盘事件