I have an iframe with designMode set to 'on'. In it, there are multiple divs, and because the iframe is editable, the user is able to type in and edit any one of those divs. I need to disable the ability for the user to edit one of the divs.
I can prevent the user from clicking on the div like this:
document.getElementById('mydiv').addEventListener('mousedown', function(event) {
event.preventDefault();
return false;
}, true);
However, the user is still able to use the keyboard arrow keys, move the cursor over to the div, and edit it. I tried firing a callback when the div receives focus, like this:
document.getElementById('mydiv').addEventListener('focus', function(event) {
...
}, true);
but that callback is never called. Then I tried to prevent keypresses:
document.getElementById('mydiv').addEventListener('keydown', function(event) {
event.preventDefault();
return false;
}, true);
but again, the callback is never called. I even tried attaching the callback to the document:
document.addEventListener('keydown', function(event) {
...
}, true);
and the callback does get called then, but I need a way to cancel the event only if the target element is the div in concern.
Any ideas on how to achieve the goal are welcome.