There is some text that looks like this
text = 'line 1' + "\r\n";
text+= 'line 2' + "\r\n";
text+= 'line 3' + "\r\n";
I have developed a function to help facilitate copying it to the clipboard
function copyToClipboard(text)
{
var copyElement = document.createElement("span");
copyElement.appendChild(document.createTextNode(text));
copyElement.id = 'tempCopyToClipboard';
angular.element(document.body.append(copyElement));
// select the text
var range = document.createRange();
range.selectNode(copyElement);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
// copy & cleanup
document.execCommand('copy');
window.getSelection().removeAllRanges();
copyElement.remove();
}
Is there a way to copy this text to the clipboard without losing the newline characters?