单击按钮打开图片另存为对话框的示例如下:
(只支持IE)
1 <html>
2 <head>
3 <title>New Document</title>
4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
5 <script language="JavaScript">
6 function downLoadImage(imagePathURL){
7 //如果中间IFRAME不存在,则添加
8 if(!getImageFrame())
9 jQuery('<iframe style="display:none;" id="_SAVEASIMAGE_TEMP_FRAME" name="_SAVEASIMAGE_TEMP_FRAME" onload="_doSaveAsImage();" width="0" height="0" src="about:blank"></iframe>').appendTo("body");
10 if(getImageFrame().src!=imagePathURL){
11 //图片地址发生变化,加载图片
12 getImageFrame().src = imagePathURL;
13 }else{
14 //图片地址没有变化,直接另存为
15 _doSaveAsImage();
16 }
17 }
18 function _doSaveAsImage(){
19 if(getImageFrame().src!="about:blank")
20 getImageFrame().document.execCommand("SaveAs");
21 }
22
23 function getImageFrame(){
24 return document.getElementById("_SAVEASIMAGE_TEMP_FRAME");
25 }
26 </script>
27 </head>
28 <body>
29 <input type="button" value="download image" onclick="downLoadImage('http://www.blogjava.net/images/blogjava_net/weiwei/46570/r_beyond1991.jpg');">
30 </body>
31 </html>