Javascript 新弹出窗口有问题吗?
在下面的程序中,如果单击“打印”,的html内容将添加到名为b.html的新弹出窗口中。它工作正常,但是b.html有一些html内容,当新的弹出窗口打开时,我会丢失这些数据。如果不丢失b.html的html内容,我如何在其中添加新的html内容 我的示例代码: 页面名称:a.htmlJavascript 新弹出窗口有问题吗?,javascript,jquery,Javascript,Jquery,在下面的程序中,如果单击“打印”,的html内容将添加到名为b.html的新弹出窗口中。它工作正常,但是b.html有一些html内容,当新的弹出窗口打开时,我会丢失这些数据。如果不丢失b.html的html内容,我如何在其中添加新的html内容 我的示例代码: 页面名称:a.html <html> <head> <script type="
<html>
<head>
<script type="text/javascript" src="js/jquery-1.6.1.min.js"> </script>
<script type="text/javascript">
$(document).ready(function()
{
$("#print").click(function()
{
var newWind=window.open('b.html', 'Print message',"left=100,screenX=200,menubar=yes, width=980,height=500, location=yes,resizable=yes,scrollbars=yes,status=yes");
var printableHTML=$("#msg").html();
newWind.document.write(printableHTML);
//newWind.append(printableHTML);
});
});
</script>
</head>
<body>
<span id="print"><u>PRINT</u></span>
<div id="msg">
<h4> I am printing this message...</h4>
</div>
</body>
</html>
<html>
<head> </head>
<body>
<h4>Hello</h4>
<div id="target"></div>
</body>
</html>
$(文档).ready(函数()
{
$(“#打印”)。单击(函数()
{
var newWind=window.open('b.html','Print message','left=100,screenX=200,menubar=yes,width=980,height=500,location=yes,resizable=yes,scrollbars=yes,status=yes');
var printableHTML=$(“#msg”).html();
newWind.document.write(可打印的HTML);
//append(可打印的HTML);
});
});
印刷品
我正在打印此消息。。。
页面名称:b.html
<html>
<head>
<script type="text/javascript" src="js/jquery-1.6.1.min.js"> </script>
<script type="text/javascript">
$(document).ready(function()
{
$("#print").click(function()
{
var newWind=window.open('b.html', 'Print message',"left=100,screenX=200,menubar=yes, width=980,height=500, location=yes,resizable=yes,scrollbars=yes,status=yes");
var printableHTML=$("#msg").html();
newWind.document.write(printableHTML);
//newWind.append(printableHTML);
});
});
</script>
</head>
<body>
<span id="print"><u>PRINT</u></span>
<div id="msg">
<h4> I am printing this message...</h4>
</div>
</body>
</html>
<html>
<head> </head>
<body>
<h4>Hello</h4>
<div id="target"></div>
</body>
</html>
你好
与其弹出一个新窗口并用想要打印的位填充它,更好的解决方案是将其打印为标准的window.print()
,并使用打印媒体样式表来显示/隐藏要打印的页面部分
@media print {
/* style sheet for print goes here */
}
与其弹出一个新窗口并用想要打印的位填充它,更好的解决方案是将其打印为标准的
window.print()
,并使用打印媒体样式表来显示/隐藏您想要打印的页面部分
@media print {
/* style sheet for print goes here */
}
改变
var newWind=window.open('b.html', 'Print message', ...
到
那你就可以了
Print_message.document.write(printableHTML);
改变
var newWind=window.open('b.html', 'Print message', ...
到
那你就可以了
Print_message.document.write(printableHTML);
使用
document.write
加载页面后,您将替换文档
使用窗口的加载事件,以便在加载文档后可以访问文档的内容:
$(newWind).load(function() {
$('#target', newWind.document).html(printableHTML);
});
使用
document.write
加载页面后,您将替换文档
使用窗口的加载事件,以便在加载文档后可以访问文档的内容:
$(newWind).load(function() {
$('#target', newWind.document).html(printableHTML);
});
如果你的帖子有一堵代码墙,如果你能链接,我们将不胜感激!什么浏览器?对我来说效果很好:如果你的帖子有一堵代码墙,如果你能链接,我们将不胜感激!什么浏览器?对我来说很好: