开发者

Disable selection on webpage BUT not on forms or people can't select input fields by mouse

开发者 https://www.devze.com 2023-03-09 13:56 出处:网络
What i\'m trying to do is to make the whole page unselectable and i\'ve done it with this: $(\'*\').disableSelection();

What i'm trying to do is to make the whole page unselectable and i've done it with this:

$('*').disableSelection();

however when you are filling out a form you can't select it by clicking, for that i've changed my code to:

$('*:not(input)').disable开发者_开发问答Selection();

but this didn't work also... i tried to call an enableSelection() for $('input') but that also couldn't override disableSelection... Any ideas?


This is a really bad idea and something that will be both difficult and CPU-intensive to perform.

.disableSelection() will disable selection of the current element and all of its children, so even if you disregard certain elements in the selector those will not be selectable if their parent have gotten its selection disabled.

Why disabling selection of a whole document is not just a bad idea but a bad practice is because it hampers usability. That is something that should be reserved to some very specific cases, such as improving security or implementing spam-protection like captchas; then you might have to cut down on usability.

The .disableSelection-method was created for the purpose to omit irrelevant content from being selected, such as specific ui elements like tabs, buttons or other descriptive ui elements. So its really a matter of improving usability, not hamper it.

In the end, this is far from a guaranteed way to stop users from selecting your content and will only make them irritated and less prone to return.


I've changed it to use :input (as that includes all types of input), but input also worked: http://jsfiddle.net/infernalbadger/kWB6g/

0

精彩评论

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