function copyWijmo() { wijmo.Clipboard.copy(createText()); alert(document.execCommand('copy') ? 'コピー成功' : 'コピー失敗'); } function copyJS() { var activeElement = document.activeElement; var textArea = document.getElementById('textArea'); textArea.value = createText(); textArea.select(); window.setTimeout(function () { activeElement.focus(); }, 100); alert(document.execCommand('copy') ? 'コピー成功' : 'コピー失敗'); } function copyWait(wait) { var activeElement = document.activeElement; var textArea = document.getElementById('textArea'); textArea.value = 'test'; textArea.select(); window.setTimeout(function () { alert(document.execCommand('copy') ? 'コピー成功' : 'コピー失敗'); }, wait); } function createText() { var text = ''; var length = Number(document.getElementById('length').value); for (var i = 0; i < length; i++) { text += 'a'; } return text; } function clearClipboard() { wijmo.Clipboard.copy(' '); document.execCommand('copy'); }
<label for="length">文字数: </label><input type="number" id="length" value="200000"><br> <button onclick="copyWijmo()">コピー(Wijmo)</button> <button onclick="copyJS()">コピー(標準機能)</button> <button onclick="copyWait(1000)">コピー(1秒後)</button> <button onclick="copyWait(2000)">コピー(2秒後)</button> <button onclick="clearClipboard()">クリップボードをクリア</button> <br><br> <textarea id="textArea" cols="30" rows="10"></textarea>