この問題の適切な解決策をお勧めします。そして、これがコードです。
<script type="text/javascript">
$(function () {
$("#btnPrint").click(function () {
var contents = $("#dvContents").html();
var frame1 = $('<iframe />');
frame1[0].name = "frame1";
frame1.css({ "position": "absolute", "top": "-1000000px" });
$("body").append(frame1);
var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument;
frameDoc.document.open();
//Create a new HTML document.
frameDoc.document.write('<html><head><title>DIV Contents</title></head>');
frameDoc.document.write('<body>');
//Append the external CSS file.
frameDoc.document.write('<link rel="stylesheet" href="Infragistics/css/structure/infragistics.css" />');
frameDoc.document.write('<link rel="stylesheet" href="Infragistics/css/structure/modules/infragistics.ui.chart1.css" />');
frameDoc.document.write('<script type="text/javascript" src="Scripts/modernizr-2.5.3.js"/>');
frameDoc.document.write('<script type="text/javascript" src="Scripts/jquery-1.9.1.min.js"/>');
frameDoc.document.write('<script type="text/javascript" src="Scripts/jquery-ui-1.8.20.min.js"/>');
//Append the DIV contents.
frameDoc.document.write(contents);
frameDoc.document.write('</body></html>');
frameDoc.document.close();
setTimeout(function () {
window.frames["frame1"].focus();
window.frames["frame1"].print();
frame1.remove();
}, 500);
});
});
</script>
よろしくお願いします