The code below prevents Ctrl+A from selecting the whole HTML page and the mouse from selecting anything, which is great.
But unfortunately Ctrl+A doesn't work on some elements in every browser as desired:
- Ctrl+A when focus is on a link, selection or button: Nothing should be selected
- Ctrl+A when focus is on an input field: The text in the current input field should be selected
With Mozilla Firefox and Internet Explorer everything works as desired. Great!
But with Google Chrome, Opera, Edge and Safari is doesn't work as desired. When the focus is on a link, selection or button, Ctrl+A selects the text of all input fields.
How can I prevent this unwanted behavior also in Google Chrome, Opera, Edge and Safari?
Remark: If the focus is on an input field, Ctrl+A should still select the text of the current input field.
And here's my code:
<html>
<head>
<style type = "text/css">
table {
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>
</head>
<body>
<table>
<tr>
<td>
Normal Text
</td>
</tr>
<tr>
<td>
<a href = "">Link</a>
</td>
</tr>
<tr>
<td>
<select>
<option value = "a">Select A
<option value = "b">Select B
</select>
</td>
</tr>
<tr>
<td>
<input type = "button" value = "Button">
</td>
</tr>
<tr>
<td>
<input type = "text" value = "Input Field 1">
<input type = "text" value = "Input Field 2">
</td>
</tr>
</table>
</body>
</html>