JS implementation picture paste to web page

This article implements the picture paste the picture on the paste board into the web page by pressing Ctrl + V, do not say direct code

         #img {width: 500px;}  JS implementation picture paste to web page插图 paste pictures by Ctrl + V    setPasteIMG () ; // get image function setPasteImg pasteboard () {// event paste document.addEventListener ( 'paste', function (event) {if (event.clipboardData || event.originalEvent) {var clipboardData = (event.clipboardData || Event.ORIGINALEVENT.CLIPBOARDDATA); if (clipboardData.items) {var blob; for (var i = 0; i < clipboardData.items.length; i++) {
       if (clipboardData.items[i].type.indexOf("image") !== -1) {
        blob = clipboardData.items[i].getAsFile();
       }
      }
      var render = new FileReader();
      render.onload = function (evt) {
       //输出base64编码
       var base64 = evt.target.result;
       document.getElementById('img').setAttribute('src',base64);
      }
      render.readAsDataURL(blob);
     }
 
    }
 
   })
 
  }
 
     

The above is all the contents of this article, I hope to help everyone, I hope everyone supports Tumi Cloud. js实现图片粘贴到网页

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment