-1
我发现了一个脚本,用于将文本框的内容写入文本文件,并显示下载链接。使用javascript将数据保存到文本文件中
但是现在我需要帮助修改此代码,以便在点击按钮后将文本文件保存在服务器中的特定位置。
下面是代码:
<html>
<head>
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
(function() {
var textFile = null,
makeTextFile = function (text) {
var data = new Blob([text], {type: 'text/plain'});
// If we are replacing a previously generated file we need to
// manually revoke the object URL to avoid memory leaks.
if (textFile !== null) {
window.URL.revokeObjectURL(textFile);
}
textFile = window.URL.createObjectURL(data);
return textFile;
};
var create = document.getElementById('create'),
textbox = document.getElementById('textbox');
create.addEventListener('click', function() {
var link = document.getElementById('downloadlink');
link.href = makeTextFile(textbox.value);
link.style.display = 'block';
}, false);
})();
}//]]>
</script>
</head>
<body>
<textarea id="textbox">Type something here</textarea>
<button id="create">Create file</button>
<a download="info.txt" id="downloadlink" style="display: none">Download</a>
<script>
// tell the embed parent frame the height of the content
if (window.parent && window.parent.parent){
window.parent.parent.postMessage(["resultsFrame", {
height: document.body.getBoundingClientRect().height,
slug: "qm5AG"
}], "*")
}
</script>
</body>
</html>
请指教。
您应该将文本发送到服务器,并在您的后端代码上执行您想要的操作。 – Gerardo