Я нашел этот скрипт онлайн, и он очень полезен.Этот скрипт создает новый файл и сохраняет форму.
В дополнение к этой форме я добавил таблицу HTML в тот же скрипт HTML.Как загрузить таблицу HTML вместе с другим содержимым этого файла index.html в тот же текстовый файл?
См. Фрагмент кода ниже:
// Current date - http://stackoverflow.com/a/4929629/412329
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = yyyy+'-'+mm+'-'+dd;
function saveFormAsTextFile()
// Based on https://thiscouldbebetter.wordpress.com/2012/12/18/loading-editing-and-saving-a-text-file-in-html5-using-javascrip/
{
var textToSave =
'---\n'+
'title: ' + document.getElementById('title').value + '\n' + // =title
'location: ' + document.getElementById('location').value + '\n' + // =location
'date: ' + today + '\n' + // =date - automatically puts today's date =todo: fix bug allowing going over 60 seconds, i.e. 61 seconds
'senses: ' + document.getElementById('senses').value + '\n' + // =senses - select menu
'tags: ' + '\n- ' + document.getElementById('tags').value.replace(/,\s/g, "\n- ") + '\n' +
// =tags
// The replace() bit above converts 'tag,tag' to '- tag\n- tag\n' with regular expressions
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
'---\n' + '\n' +
document.getElementById('content').value // =content;
var textToSaveAsBlob = new Blob([textToSave], {type:"text/plain"});
var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
var fileNameToSaveAs = document.getElementById("filename").value;
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = textToSaveAsURL;
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
function destroyClickedElement(event)
{
document.body.removeChild(event.target);
}
body {font-family:verdana, sans-serif; color:#666; background:#fafafa; padding:20px; text-align:center;}
#page {text-align:left; max-width:600px; margin:0 auto;}
h1 {font-size:16px; font-weight:normal; text-align:center;}
label {font-size:16px;}
label i {font-style:normal; display:inline-block; text-align:right; width:100px;}
label textarea {vertical-align:top;}
button {margin-left:105px; padding:5px; margin-top:5px; font-size:16px;}
input, textarea {width:400px; font-size:16px; font-family: courier, "courier new", monospace; margin:0 0 5px 0; padding:5px; border:1px solid #eee;}
select {margin:0 0 5px 0;}
@media (min-width:300px) and (max-width: 768px) {
input, textarea {width:100%;}
label i {display:block; width:auto; text-align:left;}
button {display:block; margin:0;}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Post</title>
</head>
<body>
<div id="page">
<h1>New Post</h1>
<label for="title">
<i>Title</i> <!-- =title - input example -->
<input id="title" size="40" placeholder="Title">
</label>
<br>
<label for="title">
<i>Location</i> <!-- =location - input example -->
<input id="location" size="40" placeholder="Location">
</label>
<input type="hidden" id="date" size="40"> <!-- =date - hidden input example (automatically populated with current date in yyyy-mm-dd format) -->
<br>
<label for="senses">
<i>Senses</i> <!-- =senses select menu example -->
<select name="senses" id="senses" size="1">
<option value="Touch">Touch</option>
<option value="Sound">Sound</option>
<option value="Sight">Smell</option>
<option value="Sight">Taste</option>
<option value="Sight">Sight</option>
</select>
</label>
<br>
<label for="tags">
<i>Tags</i> <!-- =tags textarea example -->
<textarea id="tags" cols="40" rows="3" placeholder="tag, tag, tag"></textarea>
</label>
<br>
<label for="content">
<i>Content</i> <!-- =content textarea example -->
<textarea id="content" cols="40" rows="10" placeholder="Write something."></textarea>
</label>
<br>
<label for="filename">
<i>Filename</i>
<input id="filename" value="" size="40" placeholder="title.md">
</label>
<button onclick="saveFormAsTextFile()">
Save to File
</button>
</div>
</body>
</html>