I saw that the input box of a website supports the function of taking screenshots and pasting them. I thought it was interesting, so I took out the code and shared it.
Unfortunately, currently only higher versions of the Chrome browser support direct pasting in this way, and other browsers are currently unable to paste (IE11 has not been tested). Of course, this enhanced user experience function is better than nothing.
Structure code of the input box:
Bind the paste event to the input box:
input.addEventListener( 'paste', function( event ){
// dosomething...
});
The Event interface object of the paste event provides a clipboardData interface, which saves the data in the system clipboard. As mentioned above, currently only higher versions of the Chrome browser can directly access the data in the system clipboard. This provides an entrance for direct interaction with the web page after taking a screenshot and saving the image to the clipboard.
The screenshot mentioned here refers to the screenshot provided by QQ or the screenshot function of the PrtScn key that comes with the system, or the screenshot function provided by other third-party software.
var file = item.getAsFile(),
reader = new FileReader();Copy code
The code is as follows: