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`.
@@ -88,39 +88,21 @@ 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;
}
