Ckeditor 4 contents to be copied to Microsoft Word docuemnt.
HTML:
<button id="copy">Copy</button>
<textarea id="textarea">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</textarea>
JS:
var editor = CKEDITOR.replace( 'textarea' );
document.getElementById('copy').onclick = function(){
var content = CKEDITOR.instances.textarea.getData(),
newElement = document.createElement("textarea");
newElement.style.position = 'absolute';
newElement.style.left = '99999px';
newElement.innerHTML = content;
document.body.appendChild(newElement)
newElement.select();
document.execCommand('copy');
}
Here is a fiddle for testing: https://jsfiddle.net/oL04y3g5/
This code will copy the html source which is:
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
Pasting this into a word document will display it as plain text not how it should look like.
How to copy the same way as if I select the text inside the box and paste it into a word document?
New contributor
user25934652 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.