Created
June 12, 2023 13:28
-
-
Save faveoled/8a47215339f5f05dfc6b56d291247818 to your computer and use it in GitHub Desktop.
Scala.js - download browser-generated file
This file contains 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
import org.scalajs.dom.document | |
import org.scalajs.dom.window | |
import org.scalajs.dom.URL | |
import org.scalajs.dom.Blob | |
def download(filename: String, contents: Blob): Unit = { | |
val elem = window.document.createElement("a").asInstanceOf[HTMLAnchorElement]; | |
elem.href = URL.createObjectURL(contents); | |
elem.download = filename; | |
document.body.appendChild(elem); | |
elem.click(); | |
document.body.removeChild(elem); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment