2017-08-30 6 views

答えて

0

ここで投げているようだ、何がプライベート'application/x-moz-file'データ型の使用です。

あなたが本当のMIMEタイプ('image/png')を使用する場合、それはスローされませんし、あなたのファイルがdataTransferオブジェクトに追加されます。

const button = document.querySelector('button'); 
 
const image = document.querySelector('img'); 
 
let file = null; 
 
button.addEventListener('click',() => { 
 
    document.execCommand('copy') 
 
}) 
 

 
document.addEventListener('copy', (event) => { 
 
    event.clipboardData.mozSetDataAt('image/png', file, 0); 
 
    console.log(event.clipboardData.files) 
 
}) 
 

 
// to avoid the big dataURI in post 
 
fetch("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Mozilla_Firefox_3.5_logo_256.png/145px-Mozilla_Firefox_3.5_logo_256.png") 
 
    .then(resp => resp.blob()) 
 
    .then(blob => file = new File([blob], 'firefox.png'));
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Mozilla_Firefox_3.5_logo_256.png/145px-Mozilla_Firefox_3.5_logo_256.png" width="20" height="20"/> 
 

 
<button>copy</button>

関連する問題