HTML generates a picture and saves it to the local method (Windows)

Source: Internet
Author: User

Recently used to save HTML as a picture to the local function (save to download directory), remember that the function IE use blob storage data, about compatibility issues see the following table, other browsers use a tag download properties new features download

as
Browser constructsFilenames Max Blob Size Dependencies
Firefox 20+ Blob Yes MiB None
Firefox < 20 Data:uri No N/A Blob.js
Chrome Blob Yes MiB None
Chrome for Android Blob Yes MiB None
Edge Blob Yes ? None
IE + + Blob Yes MiB None
Opera 15+ Blob Yes MiB None
Opera < 15 Data:uri No N/A Blob.js
Safari 6.1+* Blob No ? None
Safari < 6 Data:uri No N/A Blob.js

Step One: Introduce Html2canvas.js

Step Two: Complete the following methods to

function Downloadforjs () {

Using Html2canvas to convert HTML to canvas
Html2canvas ($ ("#ID")). Then (function (canvas) {
if (IE) {//To determine the Save method under IE
var blob = Canvas.mstoblob ();
Window.navigator.msSaveBlob (BLOB, fileName);
}else{//Other Browser Save methods
var Imguri = Canvas.todataurl ("Image/png"). Replace ("Image/png", "Image/octet-stream"); Gets the URL of the generated picture
var savelink = document.createelement (' a ');
Savelink.href =imguri;
Savelink.download = FileName; Savelink.click ();
}
});
}

More compatibility issues Reference: Https://github.com/eligrey/FileSaver.js

HTML generates a picture and saves it to the local method (Windows)

Related Article

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.