0

I don't need to constuct a json then download, I already have the url of the json, I just need to download as a file. I've been followinw some answers of other threads but I can't get it. Some answers use externals libraries, jquery, etc. Is there a clean solution via javascript?

window.location.href = "my_url";

won't do the trick. I can't manage to download the file... only it shows throught the browser. For example, I tried this: How to trigger a file download when clicking an html button or javascript

<form method="get" action="file.doc">
<button type="submit">Download!</button>
</form>

But don't know how to force the download with a json type file

Community
  • 1
  • 1
pmiranda
  • 7,602
  • 14
  • 72
  • 155
  • "another domain"? You'd need a cross-domain request, which requires that the target site allows that. you could try something silly like `` and then extract the .text() of the script node. but then the other site might not like you scraping their stuff, and send over a nasty script instead, which your browser will then happily execute. – Marc B Oct 18 '16 at 17:17
  • No, my own domain – pmiranda Oct 18 '16 at 17:21
  • I got it with this:http://stackoverflow.com/questions/11620698/how-to-trigger-a-file-download-when-clicking-an-html-button-or-javascript?rq=1 Download So simple. – pmiranda Oct 18 '16 at 17:37
  • Hmm, but it is not supported by Safari and IE11 – pmiranda Oct 18 '16 at 18:01

0 Answers0