繁体   English   中英

如何仅通过客户端使用以下代码在Chrome中打开图像的“另存为”对话框?

[英]How can I open 'Save as' dialog box for an Image in Chrome with the following Code by just using client side?

我有以下用于演示的代码,我添加了一个保存图像的按钮,以便每当用户单击“另存为”对话框时,都应出现以保存并下载客户端系统上的给定图像。

 <!DOCTYPE html>
    <html>
    <body>

    <h3>A demonstration of how to access an IMG element</h3>

    <img id="myImg" src="img_pulpit.jpg" alt="The Pulpit Rock" width="304" height="228">

    <p>Click the button to get the URL of the image.</p>

    <button onclick="myFunction()">Try it</button>

    <button onclick="saveImage()">Save Image</button>

    <p id="demo"></p>

    <script>
    function myFunction() {
      var x = document.getElementById("myImg").src;
      document.getElementById("demo").innerHTML = x;
    }
    function saveImage(){
    window.open("https://www.w3schools.com/jsref/img_pulpit.jpg").document.execCommand('SaveAs', true, "#myImg")
    }
    </script>

    </body>
    </html>

我相信问题出在您的参数中。尝试以下方法。

window.open(“ https://www.w3schools.com/jsref/img_pulpit.jpg ”).document.execCommand('SaveAs,'true',$(“#myImg”)。val())

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM