<a href=要下载的文档路径 target=_blank>名称</a>

解决方案 »

  1.   

    我要通过按钮来触发这个事件。。
    原先有段代码是在本地新键一个空白WORD文档,再打开。现在我想实现的是从服务器下载WORD文档,然后打开它。
    原来的代码:document.all.item("ifedit").value="1";
    document.all.item("zhtshow").value="clearVersion";
    var fsoFolder = new ActiveXObject("Scripting.FileSystemObject");
    //生成文件路径if (!fsoFolder.FolderExists("c:\\Program Files\\temp"))
    {
    fsoFolder.CreateFolder("c:\\Program Files\\temp");
    }   var tempfile = "c:\\Program Files\\temp\\"+document.forms[0].WebDocId.value+".html";var itemname = "Body";
    var username = document.forms[0].UserName.value; 
    editfile (tempfile, itemname, username)
      

  2.   

    <%@ page contentType="text/html; charset=gb2312"%>
    <%@ include file="/DataIni/DataOpen.jsp"%>
    <%@ include file="/ScriptLib/Init.jsp"%>
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title></title>
    <link rel="stylesheet" type="text/css" href="/StyleLib/Default_Style_Sheet.css">
    </head>
    <body>
    <%//@ include file="/TemplateLib/Wsh.jsp"%>
    <%@ include file="/TemplateLib/Head.jsp"%>
    <center>
    <br>
    <table border="0" cellpadding="0" cellspacing="0" width="80%">    
      <tr>
        <td width="100%" valign="top">测试XMLHTTP</td>
      </tr>
    </table>
    <br>
    <!--http://10.70.38.10:9002/System/Dot/Show.jsp?Id=1为输出的文件流也可以是文件路径-->
    <table border="0" cellpadding="0" cellspacing="0" width="80%">    
      <tr>
        <td width="100%" valign="top">
    <input type="text" value="http://10.70.38.10:9002/System/Dot/Show.jsp?Id=1" id="URLID">
    <input type="text" value="C:\\DownURL.doc" id="LocalURLID">
    <input type="button" value="下载" onclick="DownURL(URLID.value,LocalURLID.value);">
        </td>
      </tr>
    </table>
    <br>
    <div id=App style="border:1 solid #000000;background-color:#FFFFFF;height:200px;overflow:auto;width:80%;z-index:2" contentEditable></div>
    <script>
    function OpenFile(strFileName)
    {
    try
    {
    var WordApp=new ActiveXObject("Word.Application");
    WordApp.Application.Visible=false;
    var Doc=WordApp.Documents.Open(strFileName);
    Doc.Activate();
    Doc.Parent.Options.InsertedTextColor=4;
    Doc.Parent.Options.InsertedTextMark=2;
    Doc.Parent.Options.DeletedTextColor=4;
    Doc.Parent.Options.DeletedTextMark=1;
    Doc.TrackRevisions=true;
    Doc.PrintRevisions=true;
    Doc.ShowRevisions=true;
    Doc.Application.UserName="";
    var Range=Doc.Range();
    Range.Select();
    var Selection=WordApp.Selection;
    Selection.Copy();
    App.focus();
    document.execCommand("Paste");
    App.focus();
    WordApp.DisplayAlerts=false;
    Doc.Close();
    WordApp.DisplayAlerts=true;
    WordApp.Quit();
    }
    catch(e)
    {
    window.confirm(e);
    }
    }
    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;
    OpenFile(strLocalURL);
    }
    catch(e)
    {
    window.confirm("下载URL出错!");
    }
    //window.confirm("下载完成.");
    }
    </script>
    <br>
    <table border="0" cellpadding="0" cellspacing="0" width="80%">    
      <tr>
        <td width="100%" valign="top">测试XMLHTTP</td>
      </tr>
    </table>
    </br>
    </center>
    <%@ include file="/TemplateLib/Tail.jsp"%>
    <%@ include file="/DataIni/DataClose.jsp"%>
    </body></html>