javascript 保存文件到本地实现方法
发布时间:2015-10-14, 17:02:51 分类:HTML | 编辑 off 网址 | 辅助
正文 2336字数 510,974阅读
<script>
function SaveAs5(imgURL)
{
var oPop = window.open(imgURL,"","width=1, height=1, top=5000, left=5000");
for(; oPop.document.readyState != "complete"; )
{
if (oPop.document.readyState == "complete")break;
}
oPop.document.execCommand("SaveAs");
oPop.close();
}
</script>
<img src="t_screenshot_17616.jpg" id="DemoImg" border="0" onclick="SaveAs5(this.src)">
Run code
Cut to clipboard
<script>
function SaveAs5(imgURL)
{
var oPop = window.open(imgURL,"","width=1, height=1, top=5000, left=5000");
for(; oPop.document.readyState != "complete"; )
{
if (oPop.document.readyState == "complete")break;
}
oPop.document.execCommand("SaveAs");
oPop.close();
}
</script>
<img src="../t_screenshot_17616.jpg" id="DemoImg" border="0">
<a href="#" onclick="SaveAs5(document.getElementById('DemoImg').src)"> 点击这里下载图片 </a>
Run code
Cut to clipboard
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>
<body>
<script>
function saveFile(T,content)
{//保存
var filename=document.getElementById(T).value;
var win=window.open('','','top=10000,left=10000');
win.document.write(document.getElementById(content).innerHTML);
win.document.execCommand('SaveAs','',filename)
win.close();
}
</SCRIPT>
<form name="saveas" action="" method="post">
文件名称:<input type="text" id="title_1" value="123.html">
<br>
文件内容:<textarea id="content_1" style="height:150px;width:400px;">
新兴网络 - http://www.newxing.com/
</textarea>
<br>
<input type="button" value="保存文本" onClick=saveFile('title_1','content_1')>
</form>
</body>
</html>
Run code
Cut to clipboard
(支付宝)给作者钱财以资鼓励 (微信)→
有过 1 条评论 »