JavaScript——易班优课YOOC课群在线测试禁止右键和复制解决方案

问题描述

易班优课YOOC课群在线测试中无法选中文字和进行复制操作。

问题分析

解决方案

    //选择
    document.onselectstart= function(e){
        var e = e || window.event;
        e.returnValue = true;
        return true;
    }

    //鼠标按下
    document.onmousedown = function(e) {
        var e = e || window.event;
        e.returnValue = true;
        return true;
    }
    //鼠标右键菜单
    document.oncontextmenu = function(e) {
        var e = e || window.event;
        e.returnValue = true;
        return true;
    }

    window.onkeydown = function(e) {
        //Ctrl+S 保存
        if (e.ctrlKey && e.keyCode == 83) {
            e.returnValue = true;
            return true;
        }
        //Ctrl+P 打印
        if (e.ctrlKey && e.keyCode == 80) {
            e.returnValue = true;
            return true;
        }
        //Ctrl+C 复制
        if (e.ctrlKey && e.keyCode == 67) {
            e.returnValue = true;
            return true;
        }
    }

参考文章

https://www.cnblogs.com/mq0036/p/8482549.html

https://www.cnblogs.com/webenh/p/5899064.html

https://www.cnblogs.com/daysme/p/6272570.html

https://www.jianshu.com/p/97931bc1e438

https://blog.csdn.net/disablebb/article/details/84614317

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章