How to filter user pasted content in contenteditab

2019-07-12 02:32发布

问题:

I have a div which allow contenteditable.

<div contenteditable="true">
</div>

I would like to filter all html tags copy & pasted from user (except ), how this could achieve in Dart code?

回答1:

myDiv.onPaste.listen((e) {
  // do filtering here and then insert the result imperatively
  // one or both of the following might be necessary to prevent
  // the default paste behavior happening as well.
  e.preventDefault();
  e.stopPropagation();
});

See also:
- https://stackoverflow.com/a/3933677/217408
- Detect a paste event in a contenteditable



标签: dart