Skip to content
Snippets Groups Projects
Commit 4877a60a authored by Ken Fukuyama's avatar Ken Fukuyama Committed by Alex Ellis
Browse files

Changed the download functionality to cover IE.

Since IE doesn't work well with `.click()` (because of access denied) we
can take advantage of the `navigator.msSaveOrOpenBlob`.
https://stackoverflow.com/questions/46232980/click-giving-access-denied-in-ie11/46233123#46233123



Signed-off-by: default avatarKen Fukuyama <kenfdev@gmail.com>
parent c633fbb9
No related branches found
No related tags found
No related merge requests found
......@@ -87,40 +87,22 @@ app.controller("home", ['$scope', '$log', '$http', '$location', '$interval', '$f
var tryDownload = function(data, filename) {
var caught;
var linkElement = document.createElement('a');
try {
var blob = new Blob([data], { type: "binary/octet-stream" });
var url = window.URL.createObjectURL(blob);
linkElement.setAttribute('href', url);
linkElement.setAttribute("download", filename);
var clickEvent;
if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) { // for IE 11
clickEvent = document.createEvent("MouseEvent");
clickEvent.initMouseEvent("click", /* eventName */
true, /* bubbles */
false, /* cancelable */
window, /* view */
0,0,0,0,0, /* detail, screenX, screenY, clientX, clientY */
false, /* ctrlKey */
false, /* altKey */
false, /* shiftKey */
false, /* metaKey */
0, /* button */
null /* relatedTarget */
);
} else {
clickEvent = new MouseEvent("click", {
"view": window,
"bubbles": true,
"cancelable": false
});
if (window.navigator.msSaveBlob) { // // IE hack; see http://msdn.microsoft.com/en-us/library/ie/hh779016.aspx
window.navigator.msSaveOrOpenBlob(blob, filename);
}
else {
var linkElement = window.document.createElement("a");
linkElement.href = window.URL.createObjectURL(blob);
linkElement.download = filename;
document.body.appendChild(linkElement);
linkElement.click();
document.body.removeChild(linkElement);
}
linkElement.dispatchEvent(clickEvent);
} catch (ex) {
caught = ex;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment