Read the image from the browser clipboard and display it-for chrome

Source: Internet
Author: User

Using chrome clipboardData and file reader objects, You can implement some functions well.

Function Test (EVT) {// For chrome var clipboardData = EVT. clipboardData; For (VAR I = 0; I <clipboardData. items. length; I ++) {var item = clipboardData. items [I]; If (item. kind = 'file' & item. type. match (/^ image \ // I) {// blob is the binary image data in the clipboard var blob = item. getasfile (), reader = new filereader (); // defines the callback reader after filereader reads data. onload = function () {var shtml = ''; // The result should be a base64 encoded image document. getelementbyid ('dd '). innerhtml + = shtml;} reader. readasdataurl (BLOB); // read the binary image with filereader. After reading the binary image, the callback function defined above will be called }}}

<Textarea id = "T" onpaste = "test (event)" Cols = 60 rows = 5> </textarea> <Div id = "DD"> </Div

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.