Javascript-禁用浏览器右键和F5刷新功能

时间:2023-01-26 14:54:45

禁用浏览器页面上的右键   

 document.oncontextmenu = function(e) {

        return false ;

    }



禁用F5刷新页面, 谷歌浏览器可用

    document.onkeydown = function(e) {
        var ev = window.event || e;
        var code = ev.keyCode || ev.which;
        if (code == 116) {
            ev.keyCode ? ev.keyCode = 0 : ev.which = 0;
            cancelBubble = true;

            if (e && e.preventDefault) e.preventDefault();
            else window.event.returnValue = false ;

            return false ;
        }
    }