<!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>

解决方案 »

  1.   

    function handle(e){
    e = e || event;
    if(e.keyCode = 116){
    e.keyCode = 13;
    if(e.preventDefault){
    e.preventDefault();
    }else{
    event.returnValue = false;
    }
    }
    }
    替换原来的就可以屏蔽F5刷新了
      

  2.   

      如果是在主页里嵌套的其中一个iframe里面写这个事件有时候可以捕获到,有时捕获不到.   在主页里写是肯定捕获不到的.
      

  3.   

    common.js
    /**
     * @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>
      

  4.   

      用这个测试了一下,JS类报错.  
    window.onload = function(){
        if (document.attachEvent) 
            document.attachEvent("onkeydown", disableF5);
        else 
            document.addEventListener("keydown", disableF5, true);
    }这个里面disableF5不加参数会报错,disableF5()参数要加什么呢. 
      

  5.   

    是不是HTML中字符集设置的问题?
      

  6.   

    有件事儿提醒你一下.
    为了避免影响到画面其它的处理.
    我在JS文件中使用了 attachEvent / addEventListener来处理document.onkeydown.
    不过window.onload没有这样做.
    因此如果你的程序中有用到这些事件的话,
    你需要也使用 attachEvent / addEventListener 来处理.
      

  7.   

      3Q.   我在body里添加的onload事件把这个给覆盖了.