javascript實現(xiàn)將文件保存到本地方法匯總
更新時間:2015年07月26日 11:19:13 投稿:hebedich
本文給大家匯總介紹了3中使用javascript實現(xiàn)將文件保存到本地的方法,非常的簡單實用,有需要的小伙伴可以參考下。
下面是保存一個圖片為示例,代碼來源于網(wǎng)絡(luò),希望能夠給大家?guī)硪欢ǖ膸椭?,代碼如下:
<script type="text/javascript">
function saveFile(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>
</head>
<body>
<img src="../mytest.jpg" id="theimage" border="0">
<a href="#" onclick="saveFile(document.getElementById('theimage').src)"> 點擊這里下載圖片 </a>
</body>
</html>
方法二:
function SaveAs5(imgURL)
{
var Pop = 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();
}
<img src="t_screenshot_17616.jpg" id="DemoImg" border="0" onclick="SaveAs5(this.src)">
方法三:
function SaveAs5(imgURL)
{
var Pop = 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();
}
<img src="../t_screenshot_17616.jpg" id="DemoImg" border="0">
<a href="#" onclick="SaveAs5(document.getElementById('DemoImg').src)"> 點擊這里下載圖片 </a>
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
相關(guān)文章
使用layui的router來進行傳參的實現(xiàn)方法
今天小編就為大家分享一篇使用layui的router來進行傳參的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09

