4
4
4eloBek2015-08-11 11:28:30
JavaScript
4eloBek, 2015-08-11 11:28:30

How to insert already “clean” text into the field if it was formatted in the buffer?

I'm trying to "clear" it from tags when pasting text into a field from the buffer, but after execCommand('paste');that the code stops doing anything?
Tell me how to fix this? Or maybe there is another way to solve this issue?
Thanks in advance)

ZY The gray box is the main (if anything)
Code on jsfiddle.net

HTML:

<textarea id="txtInput0"></textarea>
<br/>
<div id="txtInput" contenteditable="true" ></div>


CSS:
#txtInput0{
    width: 200px;
    height: 30px;
}
#txtInput{
    width: 300px;
    height: 60px;
    font-size:20px;
    background-color:lightgrey;
}


JS:
$(document).keydown(function(event) {
        if ((event.ctrlKey) && (event.which == '86' || event.which == '118')) {
            if($('#txtInput').is(':focus'))  {
                
                $('#txtInput0').focus();
                $('#txtInput0').select();
                execCommand('paste');
                $('#txtInput').html($('#txtInput0').text());
                $('#txtInput').focus();
                
        }}});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Matrozov, 2015-08-11
@4eloBek

Have you looked in the direction of a slightly different solution for inserting text?
stackoverflow.com/questions/12027137/javascript-tr...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question