function Downurl (Strremoteurl, Strlocalurl) { try{ var xmlHTTP = new ActiveXObject ("Microsoft.XMLHTTP"); Xmlhttp.open ("Get", Strremoteurl, false); Xmlhttp.send (); var adodbstream = new ActiveXObject ("ADODB. Stream "); Adodbstream.type = 1;//1=adtypebinary adodbstream.open (); Adodbstream.write (xmlhttp.responsebody); Adodbstream.savetofile (Strlocalurl, 2); Adodbstream.close (); Adodbstream = null; XmlHTTP = null; } catch (e) { window.confirm ("Error downloading URL!"); } Window.confirm ("Download done.");
For example, the address to download the file is: htpp://www.baidu.com/ test.rar
We can use window.open ("Htpp://www.baidu.com/test.rar"),
But this method has no effect on Firefox and is available on IE.
If you use window.location.href= "Htpp://www.baidu.com/test.rar", some versions of Firefox are not supported.
We can write the following style:
Window.location= "Htpp://www.baidu.com/test.rar";
2. Download the file to local (default) (IE and Firefox are available)
function DownloadFile (URL) { try{ var elemif = document.createelement ("iframe"); elemif.src = URL; ElemIF.style.display = "None"; Document.body.appendChild (ELEMIF); } catch (E) { } }
JS Trigger:
<div class= "Login_center" ><a href= "Javascript:_login ()" ></a></div>
<input type= "button" value= "into 1" OnClick = "downloadFile (' Http://wan.exe ')" >
Note: In HTML, the properties of the IFRAME are SRC, but in JS, only some browsers support the modification of SRC (read is no problem), the real common is to modify the corresponding frame of the href value.
function Switchiframe () { window.frames["framename"].location.href= "action (or the name you need). aspx" }
JS Download file