Prevent user from copying text on mobile browsers

前端 未结 11 2082
陌清茗
陌清茗 2021-02-20 01:57

I\'m trying to develop a typing speed competition using JavaScript. People should write all the words they see from a div to a textarea.

To prevent cheating (like copyin

11条回答
  •  温柔的废话
    2021-02-20 02:15

    A good way to work out if a user is cheating is to compare the current input length to the last input length. You can use a data attribute to store the previous value (or length):

    
    

    jQuery:

    $(document).on('input', '.typing-only', function(){
        if((this.value.length - 1) > $(this).data('temp').length){
            alert('Cheat!');
        }
        $(this).data('temp', this.value);
    });
    

    JSFiddle demo

提交回复
热议问题