为了让我的打印预览能够接受'在样式方面,我需要在弹出窗口中包含一个我用来打印的功能:
我用来打印的功能是:
$('#printPersonnel').click(function () {
var data = document.getElementById('personnelTable').outerHTML;
var mywindow = window.open('', data);
mywindow.document.write('<html><head><title>NORA Loading</title>');
mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Content/Site.css">');
mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Scripts/examples-offline.css">');
mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Scripts/kendo.rtl.min.css">');
mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Scripts/kendo.common.min.css">');
mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Scripts/kendo.dataviz.default.min.css">');
mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Scripts/kendo.dataviz.min.css">');
mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Scripts/kendo.default.min.css">');
mywindow.document.write('</head><body>');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.focus();
mywindow.print();
mywindow.close();
return true;
});
但是,我需要添加$(document).ready
函数才能正确添加此格式(我使用的是telerik UI网格)。
这意味着我需要在我的文档中包含脚本标记。
我的问题在于尝试添加一个结束脚本标记(它将自己视为父页面的一部分,而不是在函数内部。)
关于如何实现此功能的任何建议?
我试图打印某个表标记内的所有内容,该标记在文档上格式化,可以在页面加载时被视为telerik网格
修改
我的问题在于mywindow脚本的结束标记:
mywindow.document.write('});');
mywindow.document.write('</script>'); //issue with this line/seen as esc sequence (i think)
答案 0 :(得分:1)
您可以将反斜杠与结束脚本标记一起使用。
mywindow.document.write("<script>(function(){alert('1');})();<\/script>");
答案 1 :(得分:1)
您可以将</script>
拆分为多个部分,因此不会将其解释为结束标记:
mywindow.document.write("<script>(function(){alert('1');})();" + "<" + "/script>");