简体   繁体   中英

javascript save canvas(png) from IE

I used html2canvas library. I want to store the image using the html2canvas. I success to store image from html2canvas!!! WOW!!! but.... IE has failed... I want to store all of browser.

I find navigator.msSaveBlob... I was happy~ but the happiness did not last long... base64 Encording Image is String! but I want to store pngfile! help me!!! (PS. I seriously want to slap a strong chest of IE)

~this is code~

html2canvas($("body")[0], {
        onrendered: function(canvas) {
      var img = canvas.toDataURL("image/png");
      var img2 = img.split("data:image/png;base64,")[1];



      //var blobObject = new Blob([img2],{type:"image/jpeg"});
        var blobObject = new Blob([img2]);
      window.navigator.msSaveBlob(blobObject, 'test.png'); // The user only has the option of clicking the Save button.
      alert('File save request made using msSaveBlob() - note the single "Save" button below.');
    }
});

The sad answer is... :-((

Chrome & Firefox have supported canvas.toBlob for a while, but...

IE & Edge don't yet natively support canvas.toBlob

But there are nice polyfills that bring .toBlob to IE/Edge.

I like Eli Grey's FileSaverJS and his canvas-toBlobJS .

BlueImp's JavaScript-Canvas-to-Blob is popular, too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM