开发者

How do I disable use of the space bar and enter keys on my webpage?

I'm making a site where a user repeatedly cl开发者_如何学Cicks a button to increase his/her score. Apart from using clicking bots, people can also click the button, and then without letting go of the mouse, hold down the enter or space bar key to get clicks at ridiculous speed, and can just place an object on one of these keys to hold it down all night etc.

Is there any way to stop this?

I tried adding a javascript script that disables the enter key, but it didn't work. Is there any other way to do it?

Thanks


Maybe have a look at jKey. It is a jQuery plugin to allow key shortcuts, but you will maybe be able to do what you want with it.


You can measure the time between successive clicks and if it less than say 100ms ignore the click.


could you not set a flag when the button is clicked, then start a timer? When the timer expires unset the flag again.

When the button is clicked check if the flag is set, if it is do not increase the score. you could also reset the timer to stop people just increasing their score as soon as the timer goes off.

My jQuery is not all that so I can't give an example off the top of my head.

This would have the advantage that it should work against bots as well, although the bot could just be programmed to click as soon as the flag expired...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜