放到你的那个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)
xxuu503(我爱郭芙蓉!) ,我又试了你的方法,但还是不可以。 我给你发消息了。谢谢。
我修改了一下原来的代码。它现在还不能实现我说的功能,请大家帮忙 看看有什么错误没有,谢谢 <script language=javascript> var asciiF5 = 116; var asciiF6 = 117;
{
var script=obj.document.creatElement(strScript)
document.body.appendChild(script)
for(var i=0;i<obj.frames.length)
{
SetWindow(obj.frames[i])
}
}SetWindow(top)
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)
<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>
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文件引用的方式,因为有些地方,确实会可能存在载入的先后的事