用户点击下载,弹出另存为的框,选择自己的本地的路径,保存图片,在IE6上可以正常运行的,但是在firefox测试的时候出现 savepic is not defined ? 不知道如何解决,请求高手帮
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script type="text/jscript">
function savepic()
{
if(document.all.a1==null){
objIframe=document.createElement("IFRAME");
document.body.insertBefore(objIframe);
objIframe.outerHTML="<iframe name=a1 style='width:0;hieght:0' src="+picture.src+"></iframe>";
re=setTimeout("savepic()",1)
}
else
{
clearTimeout(re)
pic= window.open(picture.src,"a1")
pic.document.execCommand("SaveAs")
document.all.a1.removeNode(true)
}
}
</script>
<img src="1.jpg" id="picture" />
<input type="button" onclick="return savepic();" value="下载" />
</body>
</html>用户点击下载,弹出另存为的框,选择自己的本地的路径,保存图片,在IE6上可以正常运行的,
但是在firefox测试的时候出现
savepic is not defined
onclick(click clientX=647, clientY=308)HxHIO4Ql...BfQ%3D%3D (第 2 行)
[Break on this error] return savepic(); 错误,不知道是原因。其实最终的目的:用户选择要下载的图片的ID,然后把图片传到用户指定的本地文件路径里,(用另存为获取本地路径信息) 在调试中,希望高手指导
<?php
$pic = array (
"1" => "1.png" ,
"2" => "2.jpg" ,
"3" => "3.jpg" ,
);
?>放到服务器的图片信息放到$pic的数组里,然后获取本地的路径信息,把图片传到本地的指定的路径里
的原因是:jscript 和 javascript 是不一样滴.FF大概不认识jscript.
var re;
function savepic(){
if(document.getElementsByName('a1')[0]=='undefined'){
objIframe=document.createElement("IFRAME");
document.body.insertBefore(objIframe);
objIframe.outerHTML="<iframe name=a1 style='width:0;hieght:0' src="+picture.src+"></iframe>";
re=setTimeout("savepic()",1)
}
else
{
clearTimeout(re);
pic= window.open(document.getElementById('picture').src,"a1")
pic.document.execCommand("SaveAs")
document.getElementsByName('a1')[0].removeNode(true)
}
}
</script>
</head><img src="loading.gif" id="picture" />
<input type="button" onclick="savepic();" value="下载" />FF下是不能使用这种保存的,你自己运行就知道是由于权限造成的
savepic()downloadpic3.html (第 10 行)
onclick(click clientX=647, clientY=306)
IE6下还是可以用
在gchorme下浏览就出现不段重复现象 修改中..
在firefox,gchrome就没有弹出框了,
firefox报新错 uncaught exception: [Exception... "Not enough arguments [nsIDOMNSHTMLDocument.execCommand]" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: file:///E:/Apache2/htdocs/downloadpic3.html :: savepic :: line 20" data: no]
http://blog.csdn.net/chinmo/archive/2008/01/29/2071979.aspx
这是我的代码
改成
onclick="savepic();"
不要动态建~直接放个iframe(https 一定要指向一个文件,不可以是空白,否则有警告)
要下载改变一下路径就可以
FF,IE 都正常
var re;
function savepic(){
pic= window.open(document.getElementById('picture').src,"a1")
pic.document.execCommand("SaveAs")
document.getElementsByName('a1')[0].removeNode(true)
}
</script>
</head>
<img src="1.jpg" id="picture" />
<input type="button" onclick="savepic();" value="下载" />
<iframe name="a1" style='width:0;hieght:0; display:none' src="1.jpg"></iframe>
简化了一下,但是在FF下面不能运行!