jquery - Getting clipboard data using javascript? -


i using html5 , jquery.

html

<canvas style="border:1px solid grey;" id="cc" width="1000" height="800"> 

javascript:

var pastecatcher; if (!window.clipboard){  if(navigator.useragent.indexof("firefox")>0){     pastecatcher = document.createelement("div");     pastecatcher.setattribute("id", "paste_ff");     pastecatcher.setattribute("contenteditable", "");     pastecatcher.style.csstext = 'opacity:0;position:fixed;top:0px;left:0px;';     pastecatcher.style.marginleft = "-20px";     document.body.appendchild(pastecatcher);     pastecatcher.focus();      document.getelementbyid('paste_ff').addeventlistener('domsubtreemodified',function(){         if(pastecatcher.children.length == 1){                         var canvas = document.getelementbyid("cc");                          var ctx = canvas.getcontext("2d");             img = pastecatcher.firstelementchild.src;             var img2 = new image();             img2.onload = function(){                 ctx.drawimage(img2, 0, 0);                 }             img2.src = img;             pastecatcher.innerhtml = '';             }         },false);     }  } 

above code working fine. when clipboard has image set canvas. if clipboard has text how can text , draw in canvas?

thanks!

as you've discovered, access clipboard varies across browsers security reasons.

even methods used read/write clipboard vary.

a workaround:

have users paste text html textarea , read textarea value.

the benefits of workaround are:

  • the user must paste somewhere anyway, let textarea.
  • the textarea can edited user if desire.
  • the textarea value not restricted security reasons, works cross-browser.

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -