D
D
dev1232019-04-07 15:11:22
JavaScript
dev123, 2019-04-07 15:11:22

How to remove html tags on paste in Wysihtml5?

Need to remove html tags when pasting text into form from clipboard.
If you catch the paste event on a simple textarea without using the wysihtml5 plugin, then you can do it like this:
html: js:
<textarea id="textarea"></textarea>

var editor = document.getElementById('textarea');
editor.addEventListener("paste", function(e) {
// отменяем дефолтное поведение
e.preventDefault();

// получаем текст из буфера
var text = e.clipboardData.getData("text/plain");

// вставляем текст в форму
document.execCommand("insertHTML", false, text);
});

When using wysihtml5, you can also track the paste event, which is built into this plugin:
var wysi_editor = new wysihtml5.Editor("node-content", {});

wysi_editor.on("paste", function(e) {
    console.log(e); 
});

and here a problem arises, the code:
console.log(e);
produces: undefined i.e. it is impossible to pass the e parameter to How then can we process the text that is in the buffer and paste it into the form?
wysi_editor.on("paste", function(e) {

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question