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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| <!DOCTYPE html>
<html>
<head>
<title>Read Text File</title>
</head>
<body>
<input class="select-zone" type="file" name="inputfile"
id="inputfile">
<br>
<textarea class="zone-txt" cols="50" rows="30" id="output"></textarea>
<br>
<button class="save-file">Enregistrer</button>
<button id="activerbouton">charger</button>
<script type="text/javascript">
document.getElementById('inputfile')
.addEventListener('change', function() {
var fr=new FileReader();
fr.onload=function(){
document.getElementById('output')
.textContent = fr.result;
}
fr.readAsText(this.files[0]);
})
</script>
</body>
</html>
<script type="text/javascript">
const link = document.querySelector('a.simple');
const saveBtn = document.querySelector('button.save-file');
let name = 'renomer le fichier';
let text = `My name in ${name}.`;
var textBlob = new Blob([text], {type: 'text/plain'});
saveBtn.addEventListener('click', function(){
var tempLink = document.createElement("a");
let textArea = document.querySelector("textarea");
var taBlob = new Blob([textArea.value], {type: 'text/plain'});
tempLink.setAttribute('href', URL.createObjectURL(taBlob));
tempLink.setAttribute('download', `${name.toLowerCase()}.txt`);
tempLink.click();
URL.revokeObjectURL(tempLink.href);
});
</script>
</div> |
Partager