I'm new to js. Please help me figure this out
WANT: Client to save an image to disk pressing a "download" button.
The image name is dynamic, from JS code on another part of the
page
DID: Read somewhere I can use document.execCommand("SaveAs") to do it
This solves it for MSIE, at least. My code is below
PROBLEM: What actually happens with MSIE is:
1) A window pops up promting me to save as.
2) The filename is correct, but the saveas type shown in the
box is limited to "html" and "txt"
3) The "image" that is saved is not an image, but an
HTML file containing the link to the image!! This is
NOT what I want!
PLEASE help. How do I get MSIE to save the actual image instead?
PS With netscape, instead of the saveas dialogue, a window opens with
the image displayed. By clicking <CTRL-S> I can save the actual image.
CODE ----
dld = function(picname, dirpath) {
// This method downloads the slide at the specified resolution.
var newwindow;
obj = dirpath+picname
newWindow = window.open( obj, "SaveImage",
"directories=no,status=no,menubar=no,toolbar=no,re sizable=no,top=100000,left=100000,width=0,height=0 ");
newWindow.document.execCommand('SaveAs', true);
newWindow.close();
return false;
}
example invocation:
<A ID="ss_view" HREF="javascript:dld('pic.jpg','../Photos/')">
<SPAN><img src="../imgs/dld.gif" alt="Download" border="0"></SPAN></A>