Is it possible to disable Ctrl + F of find in page?

后端 未结 9 1357
夕颜
夕颜 2020-12-01 12:39

I have a puzzle site and its an awful way of cheating. Its okay if only partially, but can it be done?
Something I had in mind was replacing the letters with images, but

9条回答
  •  醉话见心
    2020-12-01 12:54

    you can do it with javascript - this is only pseudocode (written in jQuery) as I'm not certain how to listen for both a ctrl AND an f, but you get the idea:

    $(body).keypress(function(e)
    {
        if (e.keyCode===17)
        {
            //ctrl has been pressed, listen for subsequent F press (keyCode 70)
            //if next keyCode===70
            return false;
        }
    });
    

    Returning false like this will stop the browser doing anything when the keys are pressed, as far as I know. you could also use e.preventDefault(); to try to prevent anything happening if return false; isn't enough.

    Hope this helps

提交回复
热议问题