Created
July 1, 2015 04:02
-
-
Save BcRikko/f7dc1af77447e976b6ff to your computer and use it in GitHub Desktop.
JSでファイルを出力する(Chrome Extensionsで使えないfileSystem APIの代用として)
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
<!doctype html> | |
<html lang="ja"> | |
<head> | |
<meta chraset="utf-8"> | |
<title>ファイル出力</title> | |
</head> | |
<body> | |
<span id="export-link"></span> | |
<script src="index.js"></script> | |
</body> | |
</html> |
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
var tasks = [ | |
{ task: 'task1', isDone: true, tags: ['project1', 'memo'] }, | |
{ task: 'task2', isDone: false, tags: ['project1', 'memo'] }, | |
{ task: 'task3', isDone: false, tags: ['project2', 'asap'] } | |
]; | |
var data = JSON.stringify(tasks); | |
var a = document.createElement('a'); | |
a.textContent = 'export' | |
a.download = 'tasks.json'; | |
a.href = window.URL.createObjectURL(new Blob([data], { type: 'text/plain' })); | |
a.dataset.downloadurl = ['text/plain', a.download, a.href].join(':'); | |
var exportLink = document.getElementById('export-link'); | |
exportLink.appendChild(a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment