Summary of the capture of copy, cut, and paste in the browser

Source: Internet
Author: User

Currently, you can use jquery. on ("copy cut paste", handlerfn) Capture. the setTimeout method is used on the Internet to obtain all the values after the input box is pasted;

The sample code for setTimeout is as follows:

$ ("Input "). off ("Paste "). on ("Paste", function (e) {setTimeout (function () {var val = $ (this ). val (); // obtain and process the value pasted into the input box}, 100 );});

Handlerfn is triggered after "right-click and paste", and "paste value is displayed in the input box". To disable this function, you can use: E. preventdefault () to disable pasting;

According to the MDN introduction, these three types of events are collectively referred to as clipboardevent. In handlerfn, data can be obtained through the getdata method. However, this API currently only supports chrome and firefox22, therefore, it is not widely used;

The sample code is as follows:

$("input").off("paste").on("paste", function(e){  var eData = e.originalEvent.clipboardData;  console.log("paste:", arguments, e.originalEvent, eData, eData.types, eData.getData("text/plain"));});

Currently, this type of documentation is called clipboard API and events, and is in the working draft State (working draft );

For details, see:

MDN https://developer.mozilla.org/en-US/docs/Web/Events/paste

W3C draft http://www.w3.org/TR/clipboard-apis/#paste-event

 

Summary of the capture of copy, cut, and paste in the browser

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.