<!DOCTYPE html>
<html>
<head>
<title>JavaScript File Download</title>
</head>
<body>
<script type="text/javascript">
function saveAs (fileContents, fileName) {
fileContents = 'data:text/plain;charset=utf-8;headers=Content-Disposition%3A%20attachment%3B%20filename%3D%22with%20spaces.txt%22%0D%0A,' + escape(fileContents);
var downloadWindow
, link = document.createElement('a');
// For non-IE
if (! window.ActiveXObject && typeof link.download === 'string') {
document.body.appendChild(link); // Firefox requires the link to be in the body
link.download = fileName;
link.href = fileContents;
link.target = '_blank';
link.click(); // simulate click
document.body.removeChild(link); // remove the link when done
} else if (!! window.ActiveXObject && document.execCommand) {
// For IE
window.open(fileContents, '_blank');
document.execCommand('SaveAs', true, fileName || fileContents);
document.close();
}
}
saveAs('Text', 'File.txt');
</script>
</body>
</html>
Комментариев нет:
Отправить комментарий