Accept drag & drop of image from another browser window

前端 未结 6 1934
夕颜
夕颜 2020-12-23 09:44

In Javascript, I know how to set up a drag & drop target that accepts file uploads from the user\'s computer. How can I set up a drop target that accepts images that are

6条回答
  •  生来不讨喜
    2020-12-23 10:15

    function drop(evt) {
        evt.stopPropagation();
        evt.preventDefault();
        var imageUrl = evt.dataTransfer.getData('URL');  // instead of 'Text'
        alert(imageUrl);
    }
    

    Seems to work in Firefox, Safari, and Chrome on Mac. Also works in Firefox, IE, and Chrome in Windows.

    Updated fiddle

提交回复
热议问题