dataTransfer is null when creating drag event programmatically

前端 未结 2 438
轻奢々
轻奢々 2020-12-19 05:21


I am trying to create a dragEvent and fire it programmatically using this code on Chrome:

var ev = document.createEvent(\"MouseEvents\");
ev.initEvent(         


        
2条回答
  •  情书的邮戳
    2020-12-19 05:43

    Unfortunately, it seems that there is no such a way to create a DataTransfer object programmatically at the moment. The description of HTML5 drag and drop interface says:

    Although, for consistency with other event interfaces, the DragEvent interface has a constructor, it is not particularly useful. In particular, there's no way to create a useful DataTransfer object from script, as DataTransfer objects have a processing and security model that is coordinated by the browser during drag-and-drops

    Please check more details here: http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#the-dragevent-and-datatransfer-interfaces

提交回复
热议问题