Laya-浏览器复制文本到剪贴板
//@param str 要复制的文本
//@return 复制是否成功
public webCopyString(str:string):boolean {
let input:string = str;
const el:any = window.document.createElement('textarea');
el.value = input;
el.setAttribute('readonly', '');
el.style.contain = 'strict';
el.style.position = 'absolute';
el.style.left = '-9999px';
el.style.fontSize = '12pt'; // Prevent zooming on iOS
const selection:any = window.getSelection();
let originalRange:any = false;
if (selection.rangeCount > 0) {
originalRange = selection.getRangeAt(0);
}
window.document.body.appendChild(el);
el.select();
el.selectionStart = 0;
el.selectionEnd = input.length;
let success:boolean = false;
try {
success = window.document.execCommand('copy');
}catch(err) {
}
window.document.body.removeChild(el);
if (originalRange) {
selection.removeAllRanges();
selection.addRange(originalRange);
}
return success;
}