<!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>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title>无标题文档 </title>
<style></style>
<script>
function handle(e){
e = e || event;
if(e.keyCode = 115){
alert("F5");
}
}
document.onkeydown = handle;
</script>
</head>
<body></body>
</html>
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title>无标题文档 </title>
<style></style>
<script>
function handle(e){
e = e || event;
if(e.keyCode = 115){
alert("F5");
}
}
document.onkeydown = handle;
</script>
</head>
<body></body>
</html>
e = e || event;
if(e.keyCode = 116){
e.keyCode = 13;
if(e.preventDefault){
e.preventDefault();
}else{
event.returnValue = false;
}
}
}
替换原来的就可以屏蔽F5刷新了
/**
* @author syukugai
*/
function disableF5(e){
e = e || window.event;
if (e.keyCode == 116) {
alert("F5");
if (document.all)
e.keyCode = 0;
if (e.returnValue)
e.returnValue = false;
else
e.preventDefault();
return false;
}
}window.onload = function(){
if (document.attachEvent)
document.attachEvent("onkeydown", disableF5);
else
document.addEventListener("keydown", disableF5, true);
}
a.html
<!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>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title>无标题文档 </title>
<script type="text/javascript" src="common.js">
</script>
</head>
<body>
<input type="text" value="">
<br>
<iframe id="f1" width="80%" src="b.html">
</iframe>
</body>
</html>
b.html
<!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>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<script type="text/javascript" src="common.js">
</script>
</head>
<body>
<input type="text" value="">
</body>
</html>
window.onload = function(){
if (document.attachEvent)
document.attachEvent("onkeydown", disableF5);
else
document.addEventListener("keydown", disableF5, true);
}这个里面disableF5不加参数会报错,disableF5()参数要加什么呢.
为了避免影响到画面其它的处理.
我在JS文件中使用了 attachEvent / addEventListener来处理document.onkeydown.
不过window.onload没有这样做.
因此如果你的程序中有用到这些事件的话,
你需要也使用 attachEvent / addEventListener 来处理.