兼容的複製文本功能

	function copyText(str) {
        let ios = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
        let Url2 = str || '';
        let oInput = document.createElement('input');
        oInput.className = 'oInput';
        oInput.value = Url2;
        document.body.appendChild(oInput);
        if (ios) {
            let range = document.createRange();
            range.selectNode(document.querySelector(".oInput"));
            let selection = window.getSelection();
            if(selection.rangeCount > 0) selection.removeAllRanges();
            selection.addRange(range);
        } else {
            oInput.select(); // 選擇對象
        }
        document.execCommand("Copy"); // 執行瀏覽器複製命令
        oInput.style.display='none';
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章