Javascript:"保存"来自网址的.PNG

时间:2018-01-23 01:49:58

标签: javascript html png

如果用户在以下确认框中单击“接受”,则应下载.png预定义文件。

<script>
if(confirm('Press accept to download the .png')){ 
 //code to download the .png
}
</script>

1 个答案:

答案 0 :(得分:1)

你的问题是双重的......

  1. 下载图片而不是显示图片。
  2. 这是通过下载属性...

    完成的
    <a id="abc" href="some URL" download="some URL">Download Image</a>
    
    1. 将DL与确认消息框链接...

    2. 全部放在一起......

      <a id="abc" href="https://ibm.box.com/shared/static/tpnmvjclp166xbtlqpx712d2qzlvpity.png" download="https://ibm.box.com/shared/static/tpnmvjclp166xbtlqpx712d2qzlvpity.png" style="visibility:hidden;">Download Image</a>
      
      
      
      <body onload="if(confirm('Press accept to download the .png')){abc.click();}">
      

      注意:我在视图中隐藏了锚点链接,其中style =&#34; visibility:hidden;&#34;

相关问题