functionDownurl (Strremoteurl, strlocalurl) {Try{ varXmlHTTP =NewActiveXObject ("Microsoft.XMLHTTP"); Xmlhttp.open ("Get", Strremoteurl,false); Xmlhttp.send (); varAdodbstream =NewActiveXObject ("ADODB. Stream "); Adodbstream.type= 1;//1=adtypebinaryAdodbstream.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"),
However, this method has no effect on Firefox, it is available on IE browser.
If you use window.location.href= "Htpp://www.baidu.com/test.rar", some versions of Firefox are not supported.
In order to solve this problem, we can change to another way
We can write the following styles:
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" ); = URL; = "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" }