Created
November 1, 2018 13:15
-
-
Save andrIvash/36c781b37cdf0017d3a8dc0236904847 to your computer and use it in GitHub Desktop.
download file by click on link event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getSomeFile().then(function(response) { | |
| if (response) { | |
| var filename = 'cc_file.xml'; | |
| var contentType = 'application/xml'; | |
| try { | |
| var linkElement = document.createElement('a'); | |
| var url = null; | |
| var blob = new Blob([response.data], {type: contentType}); | |
| if (navigator.msSaveBlob || navigator.msSaveOrOpenBlob) { | |
| navigator.msSaveOrOpenBlob(blob, filename); | |
| } else { | |
| url = window.URL.createObjectURL(blob); | |
| linkElement.setAttribute('href', url); | |
| linkElement.setAttribute("download", filename); | |
| } | |
| var clickEvent = new MouseEvent("click", { | |
| "view": window, | |
| "bubbles": true, | |
| "cancelable": false | |
| }); | |
| linkElement.dispatchEvent(clickEvent); | |
| console.log('success'); | |
| } catch (error) { | |
| console.error(error); | |
| } | |
| } | |
| }, function(error) { | |
| console.error(error); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment