[Edit]
+
0
-
0

HTML - limit element text selection area on Ctrl+a or cmd+a keys

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
<!doctype html> <html> <head> <style> [contenteditable="true"] { outline: none; } </style> <script> function isApple() { const expression = /(Mac|iPhone|iPod|iPad)/i; return expression.test(navigator.platform); } function isControl(event) { if (isApple()) { return event.metaKey; } return event.ctrlKey; // Windows, Linux, UNIX } </script> </head> <body> <p>Some text here...</p> <div contenteditable="true" spellcheck="false" onkeydown="return isControl(event) && event.key === 'a'" onpaste="return false" ondrop="return false" > Get focus on this text and press Ctrl+a or cmd+a keys. </div> <p>Some text here...</p> </body> </html> <!-- Warning: the above aproach can have some problems on some mobile devicas, e.g. Android with Google Chrome Web Browser that do not block content editing. -->
Reset