Question
How could I, when creating a file, raise a drop event for a field on which I do not have access at boot time.
More details
There is a page with a field on which the drop listener is connected, which processes the image when it is deleted. I would like to be able to use this process by inserting an image. I know how to get a file from an insert, but I don’t know how to send a drop event that will contain this same file.
The obstacles are as follows:
- The code is confusing, I cannot access the function associated with the listener by name.
- Unable to get
drop listener after attaching to element. There seems to be some way to do this in the console, but not from the script. - I do not control the rendering of pages; that is, I cannot intercept the addition of an event listener.
- Vanilla Javascript and can only work in Chrome (extension).
- This page is embedded in vanilla; those. no jQuery or anything else.
Does anyone have an idea on how to solve this problem?
I look at DragEvent , but "although this interface has a constructor, it is not possible to create a useful DataTransfer object from a script, because DataTransfer objects have a handling and security model that is coordinated by the browser during drag and drop.
I have seen a possible approach to https://stackoverflow.com/a/3129609/2129 , but I want to emulate the real drop event with its data, that is, transfer the file that I received through clipboardData.items[0].getAsFile(); instead of just text.
source share