Hi all,
I am trying to access the clipboard data on button click event in Chrome, but I am not able to access it. But if I am pressing Ctrl+v in keyboard, chrome can find the clipboard data. So for that, from a button click event I tried to call/trigger the paste event of a textbox/editor, but the clipboard is not accessible, however if I directly fire the paste event of the textbox/editor by pressing Ctrl+V, the clipboard data is accessed.
Kindly help me to get the clipboard data by trigger the paste event from a button click event. Below is my code:
This code works
---------------
$(window).on("paste", function(e) {
$.each(e.originalEvent.clipboardData.items, function() {
this.getAsString(function(str) {
alert(str);
});
});
});
When I tried to trigger the above event from a buttonclick event, it cannot access the
clipboardData, hence throws exception. Below is the code:
----------------------
$(document).ready(function(){
$("#btnSubmit").click( function() {
var event = $.Event('paste');
$("#txtText").triggerHandler(event); });
$('#txtText').on("paste", function(e) {
$.each(e.originalEvent.clipboardData.items, function() {
var dataa = e.clipboardData.getData("text/plain");
alert(dataa);
});
});
});
Thanks in advance.