xh = new ActiveXObject("Microsoft.XMLHTTP");
xh.onre">

javascript与xmlhttp联合实现文件下载

80酷酷网    80kuku.com

  javascript|xml|下载<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("");
</script>



分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: