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
Browser |
constructs | as
Filenames |
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)