使用javascript打印页面无效
Printing a page using javascript does not work
以下HTML页面应该打开http://www.seznam.cz在新窗口中,然后打开"打印"对话框以允许打印。
<html>
<head>
<script>
function printPage()
{
var newWindow = window.open("http://www.seznam.cz", "seznam");
newWindow.document.close();
newWindow.focus();
newWindow.print();
newWindow.close();
}
</script>
</head>
<body>
<a onClick="printPage(); return false;" href="">Print</a>
</body>
</html>
但是,它只打印一个空白页,右上角有"about:black",右下角有当前日期和时间。
为什么它不能按预期工作?
试试这个。。它将打印页面。您可以将其更改为"您的要求"。
<input type="button" value="Print" onclick="printPage('content');"></input>
function printPage(id)
{
var html="<html>";
html+= document.getElementById(id).innerHTML;
html+="</html>";
var printWin = window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status =0');
printWin.document.write(html);
printWin.document.close();
printWin.focus();
printWin.print();
printWin.close();
}
原因是,因为您在函数中再次关闭了窗口。删除
newWindow.document.close();
newWindow.close();
出现空白页的原因是,因为您已将空字符串指定为href
值。从标记中删除href
属性。
相关文章:
- 使用javascript将动态表从一个html页面打印到另一个html页
- JavaScript打印功能使日历停止工作
- esri javascript异步打印
- 如果我在javascript中输入无效的电子邮件或空白,如何显示特定的文本框边框红色
- 文本框不是从Javascript/Asp.net中的对话框中打印出来的
- jquery代码在Mozilla中有效,但在其他浏览器上无效
- jQuery/JavaScript在线公文包表单-打印样式表
- 如何打印嵌套对象的所有值
- 在终端中运行 JavaScript 时(使用 rhino),如何使用 print() 函数在一行中打印
- 打印预览没有应用程序页眉和页脚的html表格
- 正在打印图表上的文本
- Rhino打印功能
- 这个问号在Flow中意味着什么:“;?()=>“无效”;
- 从字符串末尾删除空白无效
- Jquery Datatables错误:无效的JSON基元:draw
- 在通过child.print()打印之前,我如何等待图像加载到我的新窗口中
- 滚动在Chrome中有效,但在Firefox或IE中无效
- 如何用javascript打印php数组
- IE9 在 iframe 中打印 PDF 时出现“无效调用对象”
- 使用javascript打印页面无效