Skip to content

Instantly share code, notes, and snippets.

@githubnando
Last active June 20, 2017 13:40
Show Gist options
  • Save githubnando/6f9e27043104f6055de8bafcb60744f9 to your computer and use it in GitHub Desktop.
Save githubnando/6f9e27043104f6055de8bafcb60744f9 to your computer and use it in GitHub Desktop.
Downlaod a file without opening a new window/popup

HTML

<iframe name="downloadIframe" id="downloadIframe" style="display: none"></iframe>

JAVASCRIPT

downloadTriggered() {
          uri = '/api/v1/users?id=1',
          downloadLink = document.createElement('a');

      downloadLink.href = uri;
      downloadLink.setAttribute('download', '');
      downloadLink.target = 'downloadIframe';
      downloadLink.click();
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment