javascript实现将文件保存到本地方法汇总
下面是保存一个图片为示例,代码来源于网络,希望能够给大家带来一定的帮助,代码如下:
<scripttype="text/javascript">
functionsaveFile(imgUrl)
{
varoPop=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>
</head>
<body>
<imgsrc="../mytest.jpg"id="theimage"border="0">
<ahref="#"onclick="saveFile(document.getElementById('theimage').src)">点击这里下载图片</a>
</body>
</html>
方法二:
functionSaveAs5(imgURL)
{
varPop=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();
}
<imgsrc="t_screenshot_17616.jpg"id="DemoImg"border="0"onclick="SaveAs5(this.src)">
方法三:
functionSaveAs5(imgURL)
{
varPop=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();
}
<imgsrc="../t_screenshot_17616.jpg"id="DemoImg"border="0">
<ahref="#"onclick="SaveAs5(document.getElementById('DemoImg').src)">点击这里下载图片</a>
以上所述就是本文的全部内容了,希望大家能够喜欢。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下