File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Saving images using JS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Saving images using JS" Watch "Saving images using JS" New topic

Saving images using JS

Bob Backlund
Ranch Hand

Joined: Jun 05, 2003
Posts: 51
I am trying to create a page that displays a list of images, under each image is a link. When you click on this link I want the IE "Save File" dialog to popup asking the user to save the image to their machine.
I've managed to get this bit to work but I can not get it to save the image, instead if tries to save the actual HTML of the page.
My script code is as follows:
function downloadImage(pid)
document.execCommand("SaveAs",null, IMAGE_NAME);
<a href="javascript ownloadImage('<%=pid%>')">Save Image</a>
Any help would be appreciated

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62106

As this has nothing to do with JSP, I'm moving it along to the HTML/Javascript forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Saving images using JS