JS打开图片另存为对话框 (转)
2012-02-13 16:19
417 查看
单击按钮打开图片另存为对话框的示例如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script language="JavaScript">
<!--
function downLoadImage(imagePathURL){
//如果中间IFRAME不存在,则添加
if(!document.getElementById("_SAVEASIMAGE_TEMP_FRAME"))
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");
if(document.all._SAVEASIMAGE_TEMP_FRAME.src!=imagePathURL){
//图片地址发生变化,加载图片
document.all._SAVEASIMAGE_TEMP_FRAME.src = imagePathURL;
}else{
//图片地址没有变化,直接另存为
_doSaveAsImage();
}
}
function _doSaveAsImage(){
if(document.all._SAVEASIMAGE_TEMP_FRAME.src!="about:blank")
document.frames("_SAVEASIMAGE_TEMP_FRAME").document.execCommand("SaveAs");
}
//-->
</script>
</head>
<body>
<input type="button" value="download image" onclick="downLoadImage('http://www.blogjava.net/images/blogjava_net/weiwei/46570/r_beyond1991.jpg');">
</body>
</html>
posted on 2010-04-15 11:58 weiwei 阅读(1459) 评论(6) 编辑 收藏
我直接把代码保存为html,但是用不了。qq401774330 回复 更多评论
# re: JS打开图片另存为对话框 2010-10-09 14:09 qq401774330
很急,麻烦指点下。qq401774330谢谢!! 回复 更多评论
# re: JS打开图片另存为对话框 2010-10-10 10:55 weiwei
@qq401774330
保存代码后,要把
<input type="button" value="download image" onclick="downLoadImage('http://www.blogjava.net/images/logo.gif');">
中的图片地址'http://www.blogjava.net/images/logo.gif'改成你本地的地址,不然,就是跨域访问。浏览器安全性阻止这个操作。 回复 更多评论
# re: JS打开图片另存为对话框 2010-10-10 11:08 weiwei
@qq401774330
把jquery去掉用JS直接操作dom会比较好:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script language="JavaScript">
<!--
function downLoadImage(imagePathURL){
//如果中间IFRAME不存在,则添加
if(!document.getElementById("_SAVEASIMAGE_TEMP_FRAME")){
var iframe = document.createElement('iframe');
iframe.setAttribute('style','display:none;');
iframe.setAttribute('id','_SAVEASIMAGE_TEMP_FRAME');
iframe.setAttribute('name','_SAVEASIMAGE_TEMP_FRAME');
iframe.setAttribute('src','about:blank');
document.appendChild(iframe);
}
if(document.all._SAVEASIMAGE_TEMP_FRAME.src!=imagePathURL){
//图片地址发生变化,加载图片
document.all._SAVEASIMAGE_TEMP_FRAME.src = imagePathURL;
_doSaveAsImage();
}else{
//图片地址没有变化,直接另存为
_doSaveAsImage();
}
}
function _doSaveAsImage(){
if(document.all._SAVEASIMAGE_TEMP_FRAME.src!="about:blank")
document.frames("_SAVEASIMAGE_TEMP_FRAME").document.execCommand("SaveAs");
}
//-->
</script>
</head>
<body>
<input type="button" value="download image" onclick="downLoadImage('tomcat.gif');">
</body>
</html> 回复 更多评论
# re: JS打开图片另存为对话框 2011-09-01 15:53 123654
为什么保存本地也不可以啊 本地图片也不行 回复 更多评论
# re: JS打开图片另存为对话框 2011-09-01 15:54 123654
为什么本地的图片也不行啊?... 回复 更多评论
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script language="JavaScript">
<!--
function downLoadImage(imagePathURL){
//如果中间IFRAME不存在,则添加
if(!document.getElementById("_SAVEASIMAGE_TEMP_FRAME"))
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");
if(document.all._SAVEASIMAGE_TEMP_FRAME.src!=imagePathURL){
//图片地址发生变化,加载图片
document.all._SAVEASIMAGE_TEMP_FRAME.src = imagePathURL;
}else{
//图片地址没有变化,直接另存为
_doSaveAsImage();
}
}
function _doSaveAsImage(){
if(document.all._SAVEASIMAGE_TEMP_FRAME.src!="about:blank")
document.frames("_SAVEASIMAGE_TEMP_FRAME").document.execCommand("SaveAs");
}
//-->
</script>
</head>
<body>
<input type="button" value="download image" onclick="downLoadImage('http://www.blogjava.net/images/blogjava_net/weiwei/46570/r_beyond1991.jpg');">
</body>
</html>
posted on 2010-04-15 11:58 weiwei 阅读(1459) 评论(6) 编辑 收藏
评论
# re: JS打开图片另存为对话框 2010-10-09 13:57 qq401774330我直接把代码保存为html,但是用不了。qq401774330 回复 更多评论
# re: JS打开图片另存为对话框 2010-10-09 14:09 qq401774330
很急,麻烦指点下。qq401774330谢谢!! 回复 更多评论
# re: JS打开图片另存为对话框 2010-10-10 10:55 weiwei
@qq401774330
保存代码后,要把
<input type="button" value="download image" onclick="downLoadImage('http://www.blogjava.net/images/logo.gif');">
中的图片地址'http://www.blogjava.net/images/logo.gif'改成你本地的地址,不然,就是跨域访问。浏览器安全性阻止这个操作。 回复 更多评论
# re: JS打开图片另存为对话框 2010-10-10 11:08 weiwei
@qq401774330
把jquery去掉用JS直接操作dom会比较好:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script language="JavaScript">
<!--
function downLoadImage(imagePathURL){
//如果中间IFRAME不存在,则添加
if(!document.getElementById("_SAVEASIMAGE_TEMP_FRAME")){
var iframe = document.createElement('iframe');
iframe.setAttribute('style','display:none;');
iframe.setAttribute('id','_SAVEASIMAGE_TEMP_FRAME');
iframe.setAttribute('name','_SAVEASIMAGE_TEMP_FRAME');
iframe.setAttribute('src','about:blank');
document.appendChild(iframe);
}
if(document.all._SAVEASIMAGE_TEMP_FRAME.src!=imagePathURL){
//图片地址发生变化,加载图片
document.all._SAVEASIMAGE_TEMP_FRAME.src = imagePathURL;
_doSaveAsImage();
}else{
//图片地址没有变化,直接另存为
_doSaveAsImage();
}
}
function _doSaveAsImage(){
if(document.all._SAVEASIMAGE_TEMP_FRAME.src!="about:blank")
document.frames("_SAVEASIMAGE_TEMP_FRAME").document.execCommand("SaveAs");
}
//-->
</script>
</head>
<body>
<input type="button" value="download image" onclick="downLoadImage('tomcat.gif');">
</body>
</html> 回复 更多评论
# re: JS打开图片另存为对话框 2011-09-01 15:53 123654
为什么保存本地也不可以啊 本地图片也不行 回复 更多评论
# re: JS打开图片另存为对话框 2011-09-01 15:54 123654
为什么本地的图片也不行啊?... 回复 更多评论
相关文章推荐
- JS打开图片另存为对话框实现代码
- 打开,另存为,属性,打印"等14个JS代码- -
- 打开,另存为,属性等14个JS代码
- 打开windows运行对话框的js
- JS基础第4课:prompt 消息对话框、打开新窗口(window.open
- js图片实时加载提供网页打开速度
- JS图片另存为(转)
- AS3使用对话框另存为本地文件(不打开网页浏览器)
- JS打开文件对话框的两种方法
- 自己写的简单通过js只提供另存为功能【避免直接打开后,文件被占用,其他用户更新不了文件信息】
- iOS UIWebView 中 js调用OC 打开相册 获取图片, OC调用js 将图片加载到html上
- js图片实时加载提供网页打开速度
- js打印,自动复制,另存为,打开源码,新窗口延迟打开等代码
- 利用对话框打开一个图像文件,并显示图片
- 双击图片弹出图片另存为对话框
- [转]打开,另存为,属性,打印等14个JS代码
- js 控制图片另存为
- js打开qq对话框方法
- PyCharm下利用pyqt对话框打开图片,显示