Created
October 27, 2014 07:46
-
-
Save rosterloh/df5db0da1d5362bfd8da to your computer and use it in GitHub Desktop.
Javascript - Creating a downloadable 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<style type="text/css">...</style> | |
<script type="text/JavaScript"> | |
window.onload = function() { | |
var txt = document.getElementById('txt'); | |
txt.value = window.onload + ''; | |
document.getElementById('link').onclick = function(code) { | |
this.href = 'data:text/plain;charset=utf-8,' | |
+ encodeURIComponent(txt.value); | |
}; | |
}; | |
main(); | |
</script> | |
</head> | |
<body> | |
<div id="txtWrap"> | |
<textarea id="txt"></textarea> | |
</div> | |
<!-- The download attribute sets the name of the file once downloaded --> | |
<a href="" id="link" download="code.txt">Download Above Code</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment