I would like to trigger onpaste event on element to retrieve data in clipboard (I want to check if image exists in clipboard and upload it into the server). It works perfect on Chrome:
$('#textarea')[0].onpaste = function(event)
{
var items = event.clipboardData.items;
if (items.length)
{
var blob = items[0].getAsFile();
var fr = new FileReader();
fr.onload = function(e)
{
alert('got it!');
}
fr.readAsDataURL(blob);
}
}
Does not work on Firefox: event.clipboardData.items
does not exists. Do you have any idea how to retrive onpaste event in element?
In order to access stored clipboard items, please open toolbar popup or right-click on an editable area and then choose clipboard manager in the right-click. Then, click on a desired clipboard item; and it will be inserted to the editable filed.
To retrieve data from the Clipboard in a single, common format. Use the GetAudioStream, GetFileDropList, GetImage, or GetText method. Optionally, use the corresponding Contains Format methods first to determine whether data is available in a particular format. These methods are available only in .
Chosen solution Firefox currently doesn't allow web pages to access the clipboard via JavaScript, so your only option would be to use the keyboard. Does Shift+Insert work in case the website is intercepting the Ctrl key?
This is because websites scripts can erase and replace what you currently have in your clipboard (data loss issue) and they can read whatever you have in your clipboard (security and privacy issue); as such, you should grant access with caution.
You need to create one contenteditable div which will hold the image on paste
var pasteCatcher = $('<div/>',{'id':'container'});
$('body').append(pasteCatcher);
var pasteCatcher = document.getElementById('container');
pasteCatcher.setAttribute("contenteditable", "");
then you need to wait for paste event and process it
window.addEventListener("paste",processEvent);
function processEvent(e) {
//some functionality
}
Also write the code to grab the image data from contenteditable div and send it to server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With