0
我的QR碼顯示在我的asp.net網頁中,但是當我嘗試打開打印對話框時,它沒有加載JavaScript和QR碼未顯示打印盒。我嘗試了所有選項來加載的jQuery中動態創建的HTML窗口,但沒有用......的代碼是這樣想要在document.write元素內執行jquery動態書寫html
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
<Scripts>
<asp:ScriptReference Path="Scripts/jquery.qrcode.js" />
<asp:ScriptReference Path="Scripts/qrcode.js" />
</Scripts>
</asp:ScriptManagerProxy>
<asp:Panel id="pnlContents" runat = "server">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table style="width: 40%;">
<tr>
<td>Name</td>
<td><h3><%#DataBinder.Eval(Container.DataItem, "Name")%></h3></td>
</tr>
<tr>
<td>Company</td>
<td><%#DataBinder.Eval(Container.DataItem, "Company") %></td>
</tr>
<tr>
<td><div id ="qrcode" ><h5>HELLO</h5>
<script type = "text/javascript">
jQuery('#qrcode').qrcode({ width: 100, height: 100, text: "Name:<%#DataBinder.Eval(Container.DataItem,"Name")%> Company:<%#DataBinder.Eval(Container.DataItem, "Company") %> Mobile:<%#DataBinder.Eval(Container.DataItem, "Mobile") %>" });
</script> </div></td>
</tr>
<tr>
<td><h3><%#DataBinder.Eval(Container.DataItem, "RegType")%></h3></td>
</tr>
</table>
<script type = "text/javascript">
function PrintPanel() {
var panel = document.getElementById("<%=pnlContents.ClientID %>");
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head><title>Print ID</title> <style type="text/css">body { margin: 264.566929px 0px 0px 0px; } </style>');
printWindow.document.write('<script type="text/javascript" src="Scripts/jquery.qrcode.js"><\/sc'+'ript>');
printWindow.document.write('<script type="text/javascript" src="Scripts/qrcode.js"><\/sc' + 'ript>');
printWindow.document.write('</head><body>');
printWindow.document.write(panel.innerHTML);
printWindow.document.write('</body></html>');
printWindow.document.close();
setTimeout(function() {
printWindow.print();
}, 500);
return false;
}
</script>
</ItemTemplate>
</asp:Repeater>
</asp:Panel>
<br />
<asp:Button ID="btnPrint" class="btn btn-warning" runat="server" Text="Print" OnClientClick = "return PrintPanel();" Visible="false"/>
您是否嘗試傳遞腳本的絕對URL? – charlietfl 2014-10-20 01:26:17
不,我沒有使用絕對網址..我從代碼背後的數據庫中獲取值..我使用nuget包來生成QR。 QR在主頁面生成,但是當打印對話框沒有顯示QR時 – user3607257 2014-10-20 07:12:57