chrome使用execCommand('copy')添加回车
chrome adds carriage returns using execCommand('copy')
当我使用document.execCommand('copy')时,chrome会在复制的文本末尾添加回车(它实际上不在HTLM中,而IE没有(正确的行为)。我做错什么了吗?
function copycode(){
var length=this.id.length;
var preid = this.id.substring(0,length-1);
var textnode=document.getElementById(preid);
textnode.setAttribute('contenteditable', 'true');
window.getSelection().removeAllRanges();
var range = document.createRange();
range.selectNode(textnode);
window.getSelection().addRange(range);
var succeed;
try {
succeed = document.execCommand("copy");
}
catch(e) {
succeed = false;
}
textnode.setAttribute('contenteditable', 'false');
}
问题不在于复制命令"document.execCommand('copy')"的执行,这很好。范围选择是个问题。
我遇到了同样的问题,并使用:element解决了它。SELECT()。例如:
创建一个文本区域并将其放在屏幕外(隐藏不起作用)。设置值并选择完整的文本区域。
var textarea = document.createElement( "textarea" );
textarea.style.height = "0px";
textarea.style.left = "-100px";
textarea.style.opacity = "0";
textarea.style.position = "fixed";
textarea.style.top = "-100px";
textarea.style.width = "0px";
document.body.appendChild( textarea );
textarea.value = textnode.innerHTML;
textarea.select();
document.execCommand('copy');
相关文章:
- 正在添加'X'按钮,在文本字段旁边使用javascript
- 如何在映射数组中添加换行符
- 正在将数据主题添加到所有项目
- ZeroClipboard-在复制之前添加到值
- 我可以在json对象中添加一个函数吗
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 正在SharePoint 2013母版页中添加JQuery移动文件
- 如何添加浮动和非浮动,其他
- 添加文字和评论功能更新Div
- 如果使用 lodash 将属性存在于另一个对象中,则向对象添加属性
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- 在函数中添加数组元素的数值
- 如何将歌曲添加到jPlayer
- 在html Select中添加搜索
- Java脚本时间添加
- chrome使用execCommand('copy')添加回车
- 如何检测第一个字符是否为回车符,并添加回车符
- 我将如何使用jquery在html文本区域中按回车符时添加换行符
- 为什么XSLT在IE10中添加换行符(回车)
- 如何在每次使用x.innerHTML时添加回车