Friday, November 23, 2018

JS/JQuery: paste the plain text only





When I copy the Word document to the text box,
in background a lot html codes and strange characters from Word
are saved.
Below is the JS/JQuery code to paste the plain text ( I have a text box with class comment):

function clickcomments($td){

    $td.find('.comment').on('paste', function(event){
            event.preventDefault();

            var text = (event.originalEvent || event).clipboardData.getData('text/plain') || prompt('Paste something..');

            window.document.execCommand('insertText', false, text);

            $(this).html($(this).html().replace(/<div>/g, '<br>').replace(/<\/div>/g, '<br>'));

    });
}        

No comments:

Post a Comment