Created
September 12, 2025 04:06
-
-
Save sketchpunk/1bf9f36e77d1f8d5c763b2dddb9b2b67 to your computer and use it in GitHub Desktop.
Download Text / Image
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 downloadText(fName: string, txt: string) { | |
| const blob = new Blob([txt], { type: 'text/plain;charset=utf-8;' }); | |
| const url = window.URL.createObjectURL(blob); | |
| const link = document.createElement('a'); | |
| link.href = url; | |
| link.download = fName; | |
| link.target = '_blank'; | |
| // link.click(); | |
| link.dispatchEvent(new MouseEvent('click')); | |
| window.URL.revokeObjectURL(url); | |
| } | |
| // dataUrl = this.env.renderer.domElement.toDataURL('image/png'); | |
| function downloadDataUrl(fName: string, dataURL: string, cleanUp = true) { | |
| const link = document.createElement('a'); | |
| link.href = dataURL; | |
| link.download = fName; | |
| link.target = '_blank'; | |
| // link.click(); | |
| link.dispatchEvent(new MouseEvent('click')); | |
| if (cleanUp) window.URL.revokeObjectURL(dataURL); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment