• Laya-浏览器复制文本到剪贴板


    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;
        }
  • 相关阅读:
    Beta冲刺 5
    Beta冲刺 4
    Beta冲刺 3
    Beta冲刺 2
    Beta冲刺 1
    项目评测博客
    Beta冲刺前准备
    Alpha 冲刺11——总结
    Alpha冲刺10
    Alpha冲刺9
  • 原文地址:https://www.cnblogs.com/kootimloe/p/13346114.html
Copyright © 2020-2023  润新知