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

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