-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsavefiletest.html
31 lines (30 loc) · 1.1 KB
/
savefiletest.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!DOCTYPE html>
<html>
<head>
<title>Download file test</title>
<meta charset="UTF-8">
<meta name="description" content="A simple test that should be disregarded."/>
</head>
<body>
<input type="text" value="wow.txt"/>
<textarea rows="8" cols="80"></textarea>
<button>Download!</button>
<script src="../sheep.js"></script>
<script>
function download(filename,text) {
// http://stackoverflow.com/questions/3665115/create-a-file-in-memory-for-user-to-download-not-through-server
var sacrifice=document.createElement('a');
sacrifice.setAttribute('href','data:text/plain;charset=utf-8,'+encodeURIComponent(text));
sacrifice.setAttribute('download',filename);
sacrifice.style.display='none';
document.body.appendChild(sacrifice);
sacrifice.click();
document.body.removeChild(sacrifice);
}
document.querySelector('button').onclick=function () {
download(document.querySelector('input').value,document.querySelector('textarea').value);
};
</script>
</body>
<!-- MADE BY SEAN -->
</html>