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 75 76 77 78 79 80 81 82 83 84 85 86
| <!doctype html>
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<style type="text/css">
textarea{
width:50%;
height:500px;
display:block;
margin:auto;
margin-bottom:15px;
border:2px ridge #aaa;
border-color:#585858;
box-shadow: 10px 10px 10px #616161;
}
</style>
<script type="text/javascript">
var nom_fichier="";
function charger(e){
var fichier = e.target.files;
var charge=new FileReader();
nom_fichier=fichier[0].name;
charge.readAsText(fichier[0]);
charge.onloadend = function(e){
document.getElementById('reate').textContent=""
document.getElementById('reate').textContent = e.target.result;
}
}
function sauver(){
var items =document.getElementById('reate').value.split('\n')
var donne=""
for(var i=0;i<items.length;i++){
donne+=items[i]+"\r\n";
}
if(navigator.msSaveOrOpenBlob){
var blobObject = new Blob([donne]);
window.navigator.msSaveOrOpenBlob(blobObject,nom_fichier);
}
else{
var blob = new Blob([donne], {type: "octet/stream"});
var url = window.URL.createObjectURL(blob);
var elem = document.createElement('a');
elem.href = url;
elem.download = nom_fichier;
var evt = new MouseEvent("click", { bubbles: true,cancelable: true,view: window,});
elem.dispatchEvent(evt);
setTimeout(function(){
window.URL.revokeObjectURL(url);
}, 100);
}
}
</script>
</head>
<body>
<br>
<input type='file' onchange='charger(event)'>
<input type='button' value="sauver" onclick='sauver(event)'>
<textarea id="reate"></textarea>
<br>
</body>
</html> |
Partager