javascript - How to get a page printed with its css intact in ruby on rails? -
javascript - How to get a page printed with its css intact in ruby on rails? -
i using ruby-on-rails-3.2 app, trying print-out of page when gets printed doesnt have css. here code
<%= link_to("print 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); homecoming 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(); homecoming true; //end }
here problem page printed before loading javascripts , css. page should print after javascript , css loaded. in advance.
try creating document css , javacstcipt
<html> <head> //your css //your scripts </head> <body> </dody> </html>
then open
window.open('/somefile.html', 'yout title maybe document', 'width=900');
then utilize jquery populate dummy print page(body area);
$(body).prepend(body_data);
maybe not loading css , javascript correctly while writing html after page loaded javascript.
keep in mind need css rules pages print correctly (colors, styles)
-webkit-print-color-adjust:exact; // chrome browser
tell me if works you!
javascript css printing ruby-on-rails-3.2
Comments
Post a Comment