quarks
quarks

Reputation: 35346

Handling paste event for a div

This is an example DIV where when selected and paste (CTRL+V) it will paste a text or image on the div:

<div contenteditable="true" id="capture" style="height: 100px; width: 100px; " 
onpaste='handlepaste(this, event)'></div

The problem here is my application will hide this div and essentially user cannot find where it is located. So is there a way that paste event is triggered and that the text or image gets pasted on this div even not selected in the page?

Update:

What I mean, I will make the div hidden for a reason that I don't need my app to display the image or text being captured. It just need it to get the captured image or text later.

Upvotes: 0

Views: 4293

Answers (1)

Sandeep Kumar
Sandeep Kumar

Reputation: 803

If your div doesn't contain anything initially then its will not appear. so you can do either of the following :

  1. Set the width and hight of the div to be appear on screen and give some differnt background and add the text &nbsp; as default text
  2. you can set the onpaste='handlepaste(this, event)' on outer div and insted of this you can pass the target div id or you can handle the target inside the handlepaste method.

like function handlepaste(event){ var target = $('#capture'); ...... }

Upvotes: 1

Related Questions