从Jquery中的Chrome浏览器访问剪贴板数据 [英] Access clipboard data from Chrome browser in Jquery

查看:507
本文介绍了从Jquery中的Chrome浏览器访问剪贴板数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试访问Chrome中按钮点击事件的剪贴板数据,但我无法访问它。但是如果我在键盘上按Ctrl + v,chrome就可以找到剪贴板数据。因此,从按钮单击事件我尝试调用/触发文本框/编辑器的粘贴事件,但是无法访问剪贴板,但是如果我通过按Ctrl + V直接触发文本框/编辑器的粘贴事件,访问剪贴板数据。



请通过触发按钮点击事件中的粘贴事件来帮助我获取剪贴板数据。以下是我的代码:



此代码有效

----------- ----

 $( window )。on(  paste function (e){
$ .each( e.originalEvent.clipboardData.items, function (){
this .getAsString( function (str){
alert(str);
});
});
});





当我尝试从buttonclick事件触发上述事件时,它无法访问 clipboardData ,因此抛出异常。以下是代码:



----------------------

 $( document )。ready( function (){
$( #btnSubmit)。click(函数(){
// $(#txtText)。trigger(paste );
var event = $ .Event(' paste');
$( #txtText).triggerHandler(event);});

$(' #txtText ')。on( paste function (e){
// e.preventDefault();
$ .each(e.originalEvent.clipboardData.items, function (){
var dataa = e.clipboardData.getData( 文本/纯);
alert(dataa);
});
});
});





提前致谢。

解决方案

window )。on( 粘贴功能(e){


.each(e.originalEvent.clipboardData.items , function (){
this .getAsString( function (str){
alert(str);
});
});
});





当我尝试从buttonclick事件触发上述事件时,它无法访问 clipboardData ,因此抛出异常。以下是代码:



----------------------

 


document )。ready(功能(){

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() {
    //$("#txtText").trigger("paste"); 
    var event = $.Event('paste');
    $("#txtText").triggerHandler(event); });
    
    $('#txtText').on("paste", function(e) {   
    // e.preventDefault();
    $.each(e.originalEvent.clipboardData.items, function() {       
         var dataa = e.clipboardData.getData("text/plain");
         alert(dataa);       
       });
    });
  });



Thanks in advance.

解决方案

(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(){


这篇关于从Jquery中的Chrome浏览器访问剪贴板数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆