我有两个功能,打印element
和打印page
打印使用jQuery
function printPage(page,redirect,dontPrint=false)
{
if($('.printThis').length == 0)
{
$('body').append('<div class="printThis hide"></div>');
}
$('.printThis').load(page,function(){
printContent($('.printThis'),redirect,dontPrint);
$('.printThis').remove();
});
}
function printContent(div_id,redirect,dontPrint=false)
{
var DocumentContainer = div_id.html();
var html = '<html><head>'+
'<link href="'+tmpl+'assets/css/print.css" rel="stylesheet" type="text/css" />'+
'</head><body style="background:#ffffff;">'+
DocumentContainer+
'</body></html>';
var WindowObject = window.open("", "PrintWindow",
"width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes");
WindowObject.document.write(html);
WindowObject.document.close();
WindowObject.focus();
setTimeout(function() {
if(!dontPrint)
{
WindowObject.print();
WindowObject.close();
}
if(redirect)
window.location.assign(redirect);
}, 50);
}
形式,我把一个按钮,在任何网页上点击功能打印页面
<button class="btn btn-primary btn-xs" onclick="printPage('/myproject/prints/bill/sales/5','')">Print Bill</button>
当用户点击另一个页面该按钮为first time
它弹出一个blank page
!!!! 任何时候,他再次点击按钮,它工作正常
你能帮助吗?
为什么这样?您可以将''添加到您的iframe中,并且它可以工作。 –
避免使用像这样的超时:用户具有所有不同类型的连接。使用'onload'函数来完成你正在寻找的东西。 – FrankerZ
如何在'.load'中使用'onload'函数,我打电话给另一个页面?和'没有iframe' –