Open the Save Image dialog using jQuery/Javascript?

后端 未结 5 352
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 16:10

When a user clicks on an image on a web page, I\'d like to trigger the browser\'s Save Image dialog and to let the user save the image on their hard drive. Is there a cross-

相关标签:
5条回答
  • 2020-12-05 16:28

    The only thing that comes to my mind is the document.execCommand("SaveAs") of Internet Explorer, you can open a window or use a hidden iframe with the url of your image, and then call it...

    Check (with IE of course) this example I've done.

    0 讨论(0)
  • 2020-12-05 16:33

    you can create a hidden file-input field and trigger() this one, when you click on your image:

    $('.yourImageClass').click(function(){
     $('.hiddenInputClass').trigger('click');
    })
    
    0 讨论(0)
  • 2020-12-05 16:36

    Google Webstore
    Github

    I made an extension that does something like this, if anyone here is still interested. It uses an XMLHTTPRequest to grab the object, which in this case is presumed to be an image, then makes an ObjectURL to it, a link to that ObjectUrl, and clicks on the imaginary link.

    In your case, you could just change ondragend to onclick and selectively add it to images.

    0 讨论(0)
  • 2020-12-05 16:46

    I don't imagine so - a lot of the basic browser functionality (eg: Print Preview) isn't available to Javascript.

    0 讨论(0)
  • 2020-12-05 16:47

    Not precisely, but you can do it by hyperlinking to the img file and setting the content-type and content-disposition headers in the server response. Try, e.g., application/x-download, plus the other headers specified here.

    0 讨论(0)
提交回复
热议问题