I have a javascript that saves the contents of a <div>
as html on click, which works just fine on chrome, but doesn't on firefox.
Please help me write a cross browser solution.
Here's my code:
$(window).load(function(){
function downloadInnerHtml(filename, elId, mimeType) {
var elHtml = document.getElementById(elId).innerHTML;
var link = document.createElement('a');
mimeType = mimeType || 'text/plain';
link.setAttribute('download', filename);
link.setAttribute('href', 'data:' + mimeType + ';charset=utf-8,' + encodeURIComponent(elHtml));
link.click();
}
var fileName = 'invo.html';
$('#downloadLink').click(function(){
downloadInnerHtml(fileName, 'Invoice','text/html');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="Invoice">
CONTENT GOES HERE
</div>
<a href="#" onclick="return false;" id="downloadLink">Download</a>