Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 292a67a

Browse files
committed
v1.0.4 Added IE 11 support thanks to benicillin in issue rainabba#3.
1 parent 31ad32b commit 292a67a

5 files changed

+67
-13
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-table2excel",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"homepage": "https://github.com/jquery-table2excel/",
55
"authors": [
66
"rainabba <[email protected]>"

dist/jquery.table2excel.js

+32-5
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,42 @@
103103
}
104104
delete e.ctx.table;
105105

106-
link = e.uri + e.base64(e.format(fullTemplate, e.ctx));
107-
a = document.createElement("a");
108-
a.download = ( e.settings.filename ? e.settings.filename : "table2excel") + ".xlsx";
109-
a.href = link;
110-
a.click();
106+
107+
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer
108+
{
109+
if (typeof Blob !== "undefined") {
110+
//use blobs if we can
111+
fullTemplate = [fullTemplate];
112+
//convert to array
113+
var blob1 = new Blob(fullTemplate, { type: "text/html" });
114+
window.navigator.msSaveBlob(blob1, getFileName(e.settings) );
115+
} else {
116+
//otherwise use the iframe and save
117+
//requires a blank iframe on page called txtArea1
118+
txtArea1.document.open("text/html", "replace");
119+
txtArea1.document.write(fullTemplate);
120+
txtArea1.document.close();
121+
txtArea1.focus();
122+
sa = txtArea1.document.execCommand("SaveAs", true, getFileName(e.settings) );
123+
}
124+
125+
} else {
126+
link = e.uri + e.base64(e.format(fullTemplate, e.ctx));
127+
a = document.createElement("a");
128+
a.download = getFileName(e.settings);
129+
a.href = link;
130+
a.click();
131+
}
132+
133+
return true;
111134

112135
}
113136
};
114137

138+
function getFileName(settings) {
139+
return ( settings.filename ? settings.filename : "table2excel") + ".xlsx";
140+
}
141+
115142
$.fn[ pluginName ] = function ( options ) {
116143
var e = this;
117144
e.each(function() {

dist/jquery.table2excel.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "http://github.com/rainabba/jquery-table2excel.git"
99
},
1010
"homepage": "https://github.com/rainabba/jquery-table2excel/",
11-
"version": "1.0.3",
11+
"version": "1.0.4",
1212
"devDependencies": {
1313
"grunt": "~0.4.5",
1414
"grunt-cli": "~0.1.13",

src/jquery.table2excel.js

+32-5
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,42 @@
9595
}
9696
delete e.ctx.table;
9797

98-
link = e.uri + e.base64(e.format(fullTemplate, e.ctx));
99-
a = document.createElement("a");
100-
a.download = ( e.settings.filename ? e.settings.filename : "table2excel") + ".xlsx";
101-
a.href = link;
102-
a.click();
98+
99+
if (typeof msie != "undefined" && msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer
100+
{
101+
if (typeof Blob !== "undefined") {
102+
//use blobs if we can
103+
fullTemplate = [fullTemplate];
104+
//convert to array
105+
var blob1 = new Blob(fullTemplate, { type: "text/html" });
106+
window.navigator.msSaveBlob(blob1, getFileName(e.settings) );
107+
} else {
108+
//otherwise use the iframe and save
109+
//requires a blank iframe on page called txtArea1
110+
txtArea1.document.open("text/html", "replace");
111+
txtArea1.document.write(fullTemplate);
112+
txtArea1.document.close();
113+
txtArea1.focus();
114+
sa = txtArea1.document.execCommand("SaveAs", true, getFileName(e.settings) );
115+
}
116+
117+
} else {
118+
link = e.uri + e.base64(e.format(fullTemplate, e.ctx));
119+
a = document.createElement("a");
120+
a.download = getFileName(e.settings);
121+
a.href = link;
122+
a.click();
123+
}
124+
125+
return true;
103126

104127
}
105128
};
106129

130+
function getFileName(settings) {
131+
return ( settings.filename ? settings.filename : "table2excel") + ".xlsx";
132+
}
133+
107134
$.fn[ pluginName ] = function ( options ) {
108135
var e = this;
109136
e.each(function() {

0 commit comments

Comments
 (0)