Skip to content

Instantly share code, notes, and snippets.

@guillaumegarcia13
Created August 2, 2018 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillaumegarcia13/ffc1556549c1e2b9a447b543950308b3 to your computer and use it in GitHub Desktop.
Save guillaumegarcia13/ffc1556549c1e2b9a447b543950308b3 to your computer and use it in GitHub Desktop.
Iframe download trick
<!-- VIEW
Trick to download document silently (without opening a new tab) -->
<iframe *ngIf="hiddenUrl" class="hidden" [src]="hiddenUrl">
</iframe>
<!-- CONTROLLER -->
public hiddenUrl: SafeUrl;
...
constructor(private sanitizer: DomSanitizer) {}
...
public foo() {
this.hiddenUrl = this.sanitizer.bypassSecurityTrustResourceUrl(downloadUrl);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment