Created
August 2, 2018 09:01
-
-
Save guillaumegarcia13/ffc1556549c1e2b9a447b543950308b3 to your computer and use it in GitHub Desktop.
Iframe download trick
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
<!-- 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