使用javascript打印页面不起作用
以下HTML页面应在新窗口中打开,然后打开“打印”对话框以允许打印使用javascript打印页面不起作用,javascript,Javascript,以下HTML页面应在新窗口中打开,然后打开“打印”对话框以允许打印 <html> <head> <script> function printPage() { var newWindow = window.open("http://www.seznam.cz", "seznam"); newWindow.document.c
<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>
函数printPage()
{
var newWindow=window.open(“http://www.seznam.cz“,”塞兹南“);
newWindow.document.close();
newWindow.focus();
newWindow.print();
newWindow.close();
}
但是,它只打印一个空白页,右上角为“about:blank”,右下角为当前日期和时间
为什么它不能按预期工作?原因是,您在函数中再次关闭了窗口。除去
newWindow.document.close();
newWindow.close();
<> P>空白页的原因是,您已经指定了一个空字符串,作为<代码> HReF值。从标记中删除
href
属性。试试这个。。它将打印页面。您可以根据需要进行更改
<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();
函数打印页(id)
{
var html=“”;
html+=document.getElementById(id).innerHTML;
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();
}可能与……有关,可能是……的问题。是的,我想这毕竟是一个原产地相同的问题。这就是为什么@collparun的版本有效,而原始版本无效。不幸的是,这不起作用。即使在我删除了这两行之后,结果仍然是一样的。我想你失去了
…
哦,谢谢你的更正@Aldiunato