[JavaScript] 在Client端列印某路徑下檔案

  • 3173
  • 0

摘要:[JavaScript] 在Client端列印某路徑下檔案

這次小弟又遇到怪問題拉,希望宰client端列印某路徑下檔案

這次當然也是利用JavaScript來完成smiley

不多說~直接看Code

<script language="javascript" type="text/javascript">
    //===============================================
    //函式名稱:列印指定的 Word 文件
    //傳入參數:docPath - Word 文件路徑
    //===============================================
    function PrintDoc(docPath)
    {
        var oHead = document.getElementsByTagName("HEAD");
        
        if(oHead)
        {
            var nNode = document.createElement("link");
            nNode.setAttribute("rel","alternate");
            nNode.setAttribute("media","print");
            nNode.setAttribute("href",docPath);
            oHead[0].appendChild(nNode);
            window.print();
            oHead[0].removeChild(nNode);
        }
    }
</script>



<input id="Button1" type="button" value="列印 Doc" onclick="PrintDoc('C:/TEST.doc')" />

 

 






Y2J's Life:http://kimenyeh.blogspot.tw/