首页 > 解决方案 > 如何打印网络路径文档客户端

问题描述

我有文件存储在 NAS 网络中。现在我想在 Internet Explorer Edge 中使用 javasrcipt 打印这些文档。以下是我尝试执行但无法打印的代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebPrintTest.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>

    printPdf = function (url) {
        var iframe = this._printIframe;
        if (!this._printIframe) {
            iframe = this._printIframe = document.createElement('iframe');
            document.body.appendChild(iframe);

            iframe.style.display = 'none';
            iframe.onload = function () {
                setTimeout(function () {
                    iframe.focus();
                    iframe.contentWindow.print();
                }, 1);
            };
        }

        iframe.src = url;
    }

    printPdf("\\ad\NAS\PrintDoc\Sample.docx");

</script>
</head>
<body>
<form id="form1" runat="server">
    <div>
    </div>
</form>
</body>

我的代码或方法有什么问题?

我收到错误

0x800a138f - JavaScript runtime error: Unable to get property 'appendChild' of undefined or null reference

 document.body.appendChild(iframe);

标签: javascriptjqueryprinting

解决方案


推荐阅读