susoxty
12-30-2005, 02:42 PM
Hello all -
Any help would be greatly appreciated, for I am fairly new to JavaScripting. I am trying to create a function that force the download of an image on his/her computer. Right now, with the function I have created, when the user clicks the "Download" link, a "Save As" box opens, but it is trying to save the HTML page, not the actual image. How can i go about reworking my code to save the image, not the HTML page. Here is what i currently have:
SORRY: HERE'S THE REAL CODE
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Cadillac Surprise & Delight</title>
</head>
<body>
<!--
/* This is the function that opens the 'save as' dialogue box in IE. */
/* It appears to fail gracefully in mozilla-based browsers but hsa not */
/* been fully tested */
-->
<script language="JavaScript">
function forceSaveAs (imagename){
document.execCommand('SaveAs',null,imagename)
}
</script>
<div>
<div class="thumb_img"><img src="thumb.jpg" border="0"></div>
<div class="thumb_txt"><a href="wallpaper.jpg" onclick="forceSaveAs('wallpaper.jpg'); return false">Download</a></div>
</div>
Any help would be greatly appreciated, for I am fairly new to JavaScripting. I am trying to create a function that force the download of an image on his/her computer. Right now, with the function I have created, when the user clicks the "Download" link, a "Save As" box opens, but it is trying to save the HTML page, not the actual image. How can i go about reworking my code to save the image, not the HTML page. Here is what i currently have:
SORRY: HERE'S THE REAL CODE
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Cadillac Surprise & Delight</title>
</head>
<body>
<!--
/* This is the function that opens the 'save as' dialogue box in IE. */
/* It appears to fail gracefully in mozilla-based browsers but hsa not */
/* been fully tested */
-->
<script language="JavaScript">
function forceSaveAs (imagename){
document.execCommand('SaveAs',null,imagename)
}
</script>
<div>
<div class="thumb_img"><img src="thumb.jpg" border="0"></div>
<div class="thumb_txt"><a href="wallpaper.jpg" onclick="forceSaveAs('wallpaper.jpg'); return false">Download</a></div>
</div>