2017-08-30 27 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>

相關問題