应该这样做.

function saveTextAsFile() {

var textToWrite = document.getElementById('textArea').innerHTML;

var textFileAsBlob = new Blob([ textToWrite ], { type: 'text/plain' });

var fileNameToSaveAs = "ecc.plist";

var downloadLink = document.createElement("a");

downloadLink.download = fileNameToSaveAs;

downloadLink.innerHTML = "Download File";

if (window.webkitURL != null) {

// Chrome allows the link to be clicked without actually adding it to the DOM.

downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);

} else {

// Firefox requires the link to be added to the DOM before it can be clicked.

downloadLink.href = window.URL.createObjectURL(textFileAsBlob);

downloadLink.onclick = destroyClickedElement;

downloadLink.style.display = "none";

document.body.appendChild(downloadLink);

}

downloadLink.click();

}

var button = document.getElementById('save');

button.addEventListener('click', saveTextAsFile);

function destroyClickedElement(event) {

// remove the link from the DOM

document.body.removeChild(event.target);

}

#textArea {

display: block;

width: 100%;

}

Notes here...

Save

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐