A textarea element contains text with html tags.
Example:
<textarea>This is a <b>sample</b>.</textarea>
How do I copy its text to the clipboard as html? So when I paste it in e.g. MS Word, sample appears bold?
A textarea element contains text with html tags.
Example:
<textarea>This is a <b>sample</b>.</textarea>
How do I copy its text to the clipboard as html? So when I paste it in e.g. MS Word, sample appears bold?
This works for me:
function copyToClip(str) {
function listener(e) {
e.clipboardData.setData("text/html", str);
e.clipboardData.setData("text/plain", str);
e.preventDefault();
}
str = str.replace(/(?:\r\n|\r|\n)/g, '<br>');
document.addEventListener("copy", listener);
document.execCommand("copy");
document.removeEventListener("copy", listener);
};
copyToClip(mytextarea.value);