0

I'm using the redactor.js-editor, which works with editable div-container. If there are multiple wrapped contenteditable container, I got the problem, that if I delete content with the backspace-button I can delete the container, so that the complete code mess up.

My question is: Can I prevent the backspace-function via javascript if the cursor is at the beginning of a div-container?

user3142695
  • 15,844
  • 47
  • 176
  • 332
  • Something similar here http://stackoverflow.com/questions/4935655/how-to-trap-the-backspace-key-using-jquery, you can probably adapt to your needs – phron Feb 16 '14 at 09:54
  • I can prevent the backspace itself. But my problem is the dependece of the cursor. I mean I only want to prevent the backspace if the cursor is at the beginning of a div-container... – user3142695 Feb 16 '14 at 10:03

1 Answers1

1
var block = this.getBlock();
var block_laenge = block.innerText.length;
var caret_offset = this.getCaretOffset(block);  
if ((e.keyCode == 8 && caret_offset == 0) || (e.keyCode == 46 && caret_offset == block_laenge)) { e.preventDefault(); }
user3142695
  • 15,844
  • 47
  • 176
  • 332