Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
573 views
in Technique[技术] by (71.8m points)

javascript - Get the pasted content on document on paste event

As mentioned in the Question how can I get the pasted content on document.As of now I am creating a text area and dblclick to get the focus into textarea and then on paste event of the textarea I am collecting the data. I dont think this is a good approach. My code is below

$('body').dblclick(function()
{
      $('#textare').focus();
});

Then 
$('#textare').keyup(function()
{
      alert( $(this).val() );
});

Please suggest me a alternative process.
I am looking for alternative like

$(document).paste(function()
{
    // Get the pasted content
});

I am using google chrome browser. I dont want to use textarea to catch the text.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can add an onpaste event to your element. It is supported by all browsers.

 onpaste="return getPastedValue(this);"


 <script type="text/javascript">
        function getPastedValue (obj) {
            alert(obj.innerHTML);
           return false;
      }
 </script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...