首页 > 解决方案 > 未捕获的 SyntaxError:尝试显示打印窗口时出现意外标识符

问题描述

尝试显示打印窗口时,我收到“未捕获的语法错误:意外的标识符”。它在本地运行良好,但是当我将它部署到 Ubuntu 服务器时,出现了错误。

function PrintDiv() {
    var divToPrint = document.getElementById('divToPrint');
    var site="<html lang='en'><body onload='window.print()'>" + divToPrint.innerHTML + "</html>";
    var popupWindow = window.open('', '_blank', 'width=800,height=900');
    popupWindow.document.write(site);
    popupWindow.document.close();
}

我这样调用 div 来显示我正在打印的内容。

<div id="divToPrint" style="display:none;">
<div style="width:700px;height:900px;">
    <h1 align="center">Active Accounts</h1>
    <table border="1" align="center" width="100%">
        <tr>
            <th>Account ID</th>
            <th>Name</th>
            <th>Type</th>
            <th>Phone</th>
            <th>Address</th>
        </tr>
        <?php foreach($accounts as $account) : ?>
            <tr>
                <td><?php print $account->get_id(); ?></td>
                <td><?php print $account->get_name(); ?></td>
                <td><?php print $account->map_attribute_type(); ?></td>
                <td><?php print $account->get_phone_number(); ?></td>
                <td><?php print $account->get_address()->get_string(); ?></td>
            </tr>
        <?php endforeach; ?>
    </table>

</div>

<input class="small button" type="button" value="print" onclick="PrintDiv();" />

标签: javascript

解决方案


推荐阅读