Skip to content

Instantly share code, notes, and snippets.

@summerscar
Last active February 19, 2019 08:00
Show Gist options
  • Select an option

  • Save summerscar/0eaa5866a8b9f9096c8ccd3c20f472dc to your computer and use it in GitHub Desktop.

Select an option

Save summerscar/0eaa5866a8b9f9096c8ccd3c20f472dc to your computer and use it in GitHub Desktop.

Revisions

  1. summerscar revised this gist Feb 19, 2019. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions downloadfile.js
    Original file line number Diff line number Diff line change
    @@ -13,4 +13,12 @@ function exportData(text) {
    saveLink.click()
    window.URL.revokeObjectURL(url)
    document.body.removeChild(saveLink)
    }

    dom.change =function(e) {
    const reader = new FileReader();
    reader.onload = function() {
    console.log(reader.result)
    }
    reader.readAsText(e.target.files[0]);
    }
  2. summerscar created this gist Feb 19, 2019.
    16 changes: 16 additions & 0 deletions downloadfile.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    function exportData(text) {
    const saveLink = document.createElement('a')
    document.body.appendChild(saveLink)

    const data = new Blob([text], { type: 'text' })
    const url = window.URL.createObjectURL(data)
    saveLink.href = url

    // File name: project-DATE-TIME
    const date = new Date()
    const timestamp = `${date.toLocaleDateString()}-${date.toLocaleTimeString()}`
    saveLink.download = `block.${timestamp}.svg`
    saveLink.click()
    window.URL.revokeObjectURL(url)
    document.body.removeChild(saveLink)
    }