Created
December 6, 2016 20:41
-
-
Save dpawluk/682220ca61b0913cf64adfeae9a457fc to your computer and use it in GitHub Desktop.
Get PDF from URL, create Object URL, then download/open in a browser window
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
| (function() { | |
| return { | |
| events: { | |
| 'app.activated':'init' | |
| }, | |
| init: function() { | |
| var self = this; | |
| this.switchTo('main'); | |
| var req = new XMLHttpRequest(); | |
| var pdf_url = this.assetURL("test2.pdf"); | |
| req.open("GET", pdf_url, true); | |
| req.responseType = "blob"; | |
| console.log(req); | |
| req.onload = function (event) { | |
| console.log("loaded"); | |
| var blob = req.response; | |
| var link = document.createElement('a'); | |
| link.href = URL.createObjectURL(blob); | |
| link.download = "name_of_file.pdf"; | |
| link.text = "Get PDF"; | |
| link.target = "_blank"; | |
| self.$("#appwrap").append(link); | |
| self.$("#appwrap a").click(); | |
| }; | |
| req.send(); | |
| } | |
| }; | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment