The problem only happens in Google Chrome, it works fine in Firefox.
Text Simple without format:
select its text and paste
Title Example
parrafe
parrafe
parrafe
New Line
Other Line
When paste in contenteditable, Chrome my texts paste return:
<div>Title Example
</div><div>parrafe
</div><div>
</div><div>parrafe
</div><div>
</div><div>parrafe
</div><div>
</div><div>
</div><div>New Line
</div><div>Other Line</div>
How prevent, my text wrappin in ?
Chrome should put line breaks
My code Html:
<article contenteditable="true">
Paste Here
</article>
<section>
<div>
<span>
<h1>select its text and paste</h1>
<h2>Title Example</h2>
<p>parrafe</p>
<p>parrafe</p>
<p>parrafe</p>
<br/>
New Line
<br/>
Other Line
</span>
</div>
</section>
My jQuery code:
$('[contenteditable]').on('paste', function(e) {
e.preventDefault();
var text = '';
if (e.clipboardData || e.originalEvent.clipboardData) {
text = (e.originalEvent || e).clipboardData.getData('text/plain');
} else if (window.clipboardData) {
text = window.clipboardData.getData('Text');
}
text = text.replace(/<[^>]*>?/gm, '');
if (document.queryCommandSupported('insertText')) {
document.execCommand('insertText', false, text);
} else {
document.execCommand('paste', false, text);
}
});
$('[contenteditable]').keydown(function(e) {
if (e.keyCode === 13) {
document.execCommand('insertHTML', false, '<br><br>');
return false;
}
});
My jsFiddle:
, I need that. – Renato Ramos Puma Sep 20 '19 at 16:50
Title Example
parrafe
parrafe
parrafe
New Line
Other Line
". I need the same, without – Renato Ramos Puma Sep 20 '19 at 16:56