Make all EXCEPT <input> text inaccessible in Internet Explorer?

I have a website where I want to disconnect users from selecting EXCEPT content for input areas. I currently have CSS for disabling user selection:

-webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -o-user-select: none; user-select: none; 

However, this does NOT apply to Internet Explorer; so i need to implement some javascript:

 <body onselectstart="return false;"> 

Using CSS and JavaScript, I can make all content inaccessible to all popular browsers. BUT, this code also makes areas non-selectable, which is the main case of poor use. I use CSS to select input areas:

 -webkit-user-select: text; -khtml-user-select: text; -moz-user-select: text; -o-user-select: text; user-select: text; 

.. and, as you might expect, this does not apply to Internet Explorer, since I used JavaScript to disable all the content that you can select.

What can I do to make all content inaccessible except input areas?

+4
source share
3 answers

Since the event bubbles up to the body and does not appear there, I think you can check the name of the node for the actual target of the node and not return false for events occurring on specific nodes:

 <body onselectstart="if ((event.target || event.srcElement).nodeName !== 'INPUT') return false;"> 
+2
source

Try the following: oncontextmenu = "return false;"

Put this in your body tag, then use something like:

 e.cancelBubble = true; if (e.stopPropagation) e.stopPropagation(); 

in javascript function for input elements you want to select. This should stop the propagation of the event that will trigger the body tag.

+2
source

You can add the proprietary IE attribute unselectable="on" to any element that you want to make inaccessible in IE:

 <p unselectable="on">I don't want IE users to easily select this text for some reason.</p> 

See Non-highlighting of things in IE for more details.

If you are doing this from javascript, be sure to use el.setAttribute("unselectable","on") . Just using el.unselectable="on" will not work.

0
source

Source: https://habr.com/ru/post/1381398/


All Articles