简体   繁体   中英

How to create event with filled property dataTransfer?

I have local html file with javascript code.

I should cover drag & drop by tests.

It uses only IE.

In javascript code event "drop" is caught and content of dataTransfer (e.dataTransfer.getData("Text")) is analysed.

In test I simulate event with next code:

event = document.createEventObject();

Here event which contains dataTransfer == null is created.

Write is impossible, because property is read only.

target.fireEvent("ondrop", event);

Event is fired in javascript code, but dataTransfer is null.

I should put some test element in dataTransfer.

How can I resolve this problem?

You could try using the CustomEvent interface, I'm not sure if it works in IE though.

var event = new CustomEvent('build', { 'detail': elem.dataset.time });

https://developer.mozilla.org/en-US/docs/Web/API/document.createEvent#Adding_custom_data_.E2.80.93_CustomEvent

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM