
我正在使用ruby-on-rails-3.2应用程序,试图打印出一个页面,但当它被打印出来时,它没有css。以下是我的代码
<%= link_to("Print this Page", "#", :onclick =>"PrintElem('.PrintElem','News Details')") %>
function PrintElem(news_heading, reporters_details, full_news_text, title)
{
heading = jQuery('head').html();
body_data = jQuery('body').html();
Popup(heading, body_data);
return true;
}
function Popup(news_heading, body_data)
{//start
// var mywindow = window.open('','printwindow');
mywindow = window.open('#','printing','height=900,width=900,scrollbars=1');
mywindow.document.write('<html><head>'+heading+'</head><body onload="window.print();">');
mywindow.document.write(body_data);
mywindow.document.write('</body></html>')
mywindow.onload = function() { mywindow.print(); }
mywindow.document.close();
return true;
//end
}这里问题是在加载javascripts和css之前打印页面。此页应在所有javascript和css加载后打印。提前谢谢。
发布于 2014-06-25 16:30:34
尝试使用css和javacstcipt创建文档
<html>
<head>
//Your css
//Your scripts
</head>
<body>
</dody>
</html>然后打开
window.open('/somefile.html', 'Yout Title maybe from the document', 'width=900');然后使用jQuery填充虚拟打印页面(正文区域);
$(body).prepend(body_data);也许在用javascript加载页面后编写所有的html时,你没有正确加载css和javascript。
请记住,您需要一些css规则才能正确打印页面(颜色、样式)
-webkit-print-color-adjust:exact; // For chrome browser告诉我它对你是否有效!
https://stackoverflow.com/questions/24393845
复制相似问题