GetFile.wsc
复制代码 代码如下:
<?xmlversion="1.0"encoding="gb2312"?>
<component>
<?componenterror="true"debug="true"?>
<public>
<propertyname="Referer"/>
<propertyname="Content"/>
<propertyname="Data"/>
<methodname="GetFile">
<parametername="URL"/>
</method>
<methodname="Save">
<parametername="Path"/>
</method>
</public>
<implementstype="Behavior">
<eventname="ondowncomplete"/>
</implements>
<objectprogid="Microsoft.XmlHttp"id="Http"/>
<scriptlanguage="javascript">
<![CDATA[
varReferer,Content,Data;
varStream=newActiveXObject("ADODB.Stream");
Stream.Type=1;
functiononReady()
{
if(Http.readyState==4)
{
Content=Http.responseText;
Data=Http.responseBody;
fireEvent("ondowncomplete");
Http.abort();
}
}
functionGetFile(URL)
{
Http.onreadystatechange=onReady;
Http.open("GET",URL,true,"","");
if(Referer)Http.setRequestHeader("Referer",Referer);
Http.send(null);
}
functionSave(Path)
{
Stream.Open();
Stream.Write(Data);
Stream.SaveToFile(Path,2);
Stream.Close();
}
]]>
</script>
</component>
test.hta
复制代码 代码如下:
<html><head><script>
varDown=document.createElement("Comment");
document.lastChild.lastChild.appendChild(Down);
Down.style.behavior="url(GetFile.wsc)";
Down.ondowncomplete=function()
{
//document.write(Down.Content);
Down.Save(SaveTo.value);
Go.disabled=0;
alert("OK");
}
functionGetFile()
{
Go.disabled=1;
Down.Referer=Referer.value;
Down.GetFile(URL.value);
}
</script>
</head><body>
URL:<inputid="URL"size="50"value="http://www.booksky.biz/SendFile.aspx?FileID=15531"><br>
Referer:<inputname="Referer"size="40"value="http://www.booksky.biz"><br>
SaveTo:<inputname="SaveTo"size="40"value="D:Test.gif"><br>
<inputid="Go"type=buttonvalue="下载"onclick="GetFile()">
</body></html>
【通过修改referer下载文件的方法】相关文章:
★ 使用RequireJS优化JavaScript引用代码的方法
★ JavaScript中使用Math.PI圆周率属性的方法
★ JavaScript实现点击自动选择TextArea文本的方法