从我的网页我有一个打印图标。点击图标,我打开一个弹出页面"Print_content.aspx"
我将查询字符串传递给弹出页面?print =父页面的URL和DIV的名称来获取父页面"#subcontent",并将DIV子内容(父页面)中的内容加载到DIV站点加载器中,这是在我的弹出页面。
这在Mozilla和Chrome中完美地工作。但不能用IE
Jquery在弹出页面:
var value = window.location.search;
$(document).ready(function () {
$("#siteloader").load(value.replace("?print=", "") + " #subcontent");
});
</script>
Print_content.aspx的整个标记
<script type="text/javascript" src="../Scripts/jquery-1.7.2.min.js"></script>
<link href="../print.css" rel="stylesheet" type="text/css" />
<title></title>
</head>
<body>
<table>
<tr>
<td>
<div id="logo">
</div>
</td>
</tr>
<tr>
<td align="center">
<a runat="server" id="img_Print" onclick="window.print()">
<img id="Img1" runat="server" src="/image/btn_print.gif" /></a>
</td>
</tr>
<tr>
<td align="left">
<div id="siteloader">
</div>
</td>
</tr>
</table>
<script type="text/javascript">
var value = window.location.search;
$(document).ready(function () {
$("#siteloader").load(value.replace("?print=", "") + " #subcontent");
});
</script>
<div id="div-overlay" style="position: absolute; top:130px; height: 100%; width: 100%; z-index: 200; opacity: 0.0;background-color:Gray;"> </div>
</body>
</html>
您的意思是用var value = window.location.href
代替吗?
另一种从PARENT页打印内容到POPUP页的方法如下:
$("a.doPrint").click(function(e) {
e.preventDefault();
var printSource = $("#myElementToPrint");
var printWindow = window.open("", "printWindow", "width=700,height=400,location=no,menubar=yes,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no");
if(!printWindow) alert("Please enable popups to access this feature.");
else {
printWindow.onload = function() {
setTimeout(function() {
if (printWindow.screenX === 0) {
alert("Please enable popups to access this feature.");
}
}, 0);
};
printWindow.document.write('<html><head><title>Printing Page</title></head><body>' + printSource.html() + '</body></html>');
printWindow.print();
}
return false;
});