не может скопировать содержимое текстовой области в буфер обмена, используя приведенный ниже код.
<script>
function copyText()
{
document.getElementById('in').click();
call();
}
function call()
{
if(getComputedStyle(document.getElementById('butt')).opacity>0.5)
{setTimeout(call,100);return;}
var ta=window.document.createElement("textarea");
window.document.body.appendChild(ta);
ta.value="this text should be in clipboard";
ta.focus();
ta.selectionStart=0;
ta.selectionEnd=ta.value.length;
ta.addEventListener('keypress', function(){window.document.execCommand('copy');});
var event = new Event('keypress');
ta.dispatchEvent(event) ;
}
</script>
<button id='butt' onClick='copyText()'>copy text</button>
<input id='in' type='file' style='display:none;'/>
<style>
#butt
{opacity:0.5;}
#butt:hover
{opacity:1;}
</style>
в то время как если я добавлю alert()
после setTimeout(call,100)
в блоке if перед оператором return.
Текст копируется.
попробовал на chrome,opera и firefox, все браузеры ответили одинаково.
Я использую приведенную выше структуру для копирования закодированного в base64 текста файла, открытого пользователем.