[英]JS: insert a line break into copied text
I'm trying to implement copying text with line brakes to the clipboard and then to paste it into a simple text file under Windows: 我正在尝试使用行制动器将文本复制到剪贴板,然后将其粘贴到Windows下的简单文本文件中:
function copyText(name, value){
var text = name + ': ' + value + '\r\n';
var text += 'next line';
if (document.body.createTextRange){
var cont = document.createElement('p');
var textNode = document.createTextNode(text);
cont.appendChild(textNode);
document.body.appendChild(cont);
var textRange = document.body.createTextRange();
textRange.moveToElementText(cont);
textRange.execCommand('copy');
document.body.removeChild(cont);
}
}
but after inserting in the file there is no line breaks. 但是插入文件后没有换行符。 how to fix it?
如何解决?
查看是否可行:
var cont = document.createElement('pre');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.