GithubHelp home page GithubHelp logo

miltonbhowmick / copy-paste-image-field Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 3.14 MB

A javascript tricks to copy and paste image in text field

Home Page: https://miltonbhowmick.github.io/copy-paste-image-field/

HTML 31.10% JavaScript 17.91% CSS 50.99%
javascript javascript-tricks copy-paste-image javascript-copy-image javascript-paste-image

copy-paste-image-field's Introduction

COPY IMAGE - PASTE IMAGE

A mini tricks between input field and img tag in html to show an image.

GitHub Repo stars

Play it by yourself

Demo

How it works

Which logic helps

  • Use event.clipboardData or event.originalEvent.clipboardData.
  • event.clipboardData or event.originalEvent.clipboardData contains items if they have. If they contain, write var items = (event.clipboardData || event.originalEvent.clipboardData).items;.
  • Now, you have items. Its items, you can do a loop ๐Ÿ’โ€โ™‚๏ธ. You can see each element by index of that loop items[index].
  • We need only file item from items[index]. So, you may do a check like this if (item.kind === 'file').
  • Get the blob data of this file item by writing var blob = item.getAsFile();.
  • As it is a file, you have to read the file item. To read a file item, Javascript has a class FileReader(). Write var reader = new FileReader();.
  • How can you see If a file is not loaded ๐Ÿคซ?. Write reader.onload = function (event) {};.
  • Inside the above onload function, you can write document.getElementById("pastedImage").src = event.target.result; of your image html tag <img id="pastedImage"/>.
  • Then copy image and paste image and BOOM!!!.

copy-paste-image-field's People

Contributors

miltonbhowmick avatar miltonbhowmickb avatar

Stargazers

Roman avatar Nur Shuvo avatar Md Abu Kausar avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.