Heim >Web-Frontend >js-Tutorial >Javascript-Implementierung zum Speichern von Dateien in lokalen Methoden. Zusammenfassung_Javascript-Kenntnisse
Das Folgende ist ein Beispiel für das Speichern eines Bildes. Ich hoffe, es kann allen helfen. Der Code lautet wie folgt:
<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>