I have some JavaScript code as given under first code snippet, that works in latest Chrome but not in latest FireFox. This code is exporting data to xls
file using Blob object. The strange thing is that in FireFox, the code does not throw any error but does nothing as it executes all the lines successfully i.e. no export happens.
A demo for this question is at this URL: http://js.do/sun21170/84920
If you run the code in above demo in Chrome, it will download the file newfile.xls
( allow popups in Chrome).
Question: What change I need to make in Blob Code
given below, in order to make it work in FireFox? I tried using type: 'application/octet-stream'
and also type: 'text/plain'
, but both did not help in FireFox.
The variable table
in code snippet below holds a string that is the html for rendering a table including html and body tags.
Blob Code for exporting (not working in FireFox)
//export data in Chrome or FireFox
//this works in Chrome but not in FireFox
//also no errors in firefox
sa = true;
var myBlob = new Blob( [table] , {type:'text/html'});
var url = window.URL.createObjectURL(myBlob);
var a = document.createElement(a);
document.body.appendChild(a);
a.href = url;
a.download = newfile.xls;
a.click();
window.URL.revokeObjectURL(url);