html - get all images from div and replace src with base64 using javascript -


here trying do

<!--html-->  <div class="col-md-11" id="divcontent">     <textarea class="ckeditor form-control" name="editor1" id="editor1" rows="6">         <p>this test image</p>         <img src="https://www.google.com.au/images/srpr/logo11w.png" />     </textarea>  </div>  <!--javascript-->  <script>         function parseimages()         {             //var html = ckeditor.instances.editor1.getdata();             var images = document.getelementbyid("divcontent").getelementsbytagname('img');             (i = 0, len = images.length; < len; i++)             {                 var newsrc= images[i].src.replace('data:image/png;base64,'+ converttobase64(images[i].src));                 alert(newsrc);             }         }          //convert image base 64         function converttobase64(url)         {             var img = new image();             img.src = url;             img.onload = function () {                 var canvas = document.createelement("canvas");                 canvas.width = this.width;                 canvas.height = this.height;                  var ctx = canvas.getcontext("2d");                 ctx.drawimage(this, 0, 0);                  var dataurl = canvas.todataurl("image/png");                  dataurl.replace(/^data:image\/(png|jpg);base64,/, "");             }         }     </script> 

i can't catch images inside var images. text area ck text editor, tried taking images id="editor1" didn't work either, if have solution please advise.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -