0

In my Rails app I have an onClick function that sends to a printer a div of the page identified by an id. My problem is that it is not displaying the print preview in the Rails view.

This is my JS function:

function printDiv(divName) {
 var printContents = document.getElementById(divName).innerHTML;
 var originalContents = document.body.innerHTML;

 document.body.innerHTML = printContents;

 window.print();

 document.body.innerHTML = originalContents;}

How can I solve this? Thanks!

Federico
  • 62
  • 7
  • 1
    Check this post http://stackoverflow.com/questions/468881/print-div-id-printarea-div-only – ramongr Mar 28 '17 at 17:57
  • can you show some more info on where you are putting this function and where you call it? – max pleaner Mar 28 '17 at 18:10
  • 2 things: (1) Read [ask]; pay special attention to the bit about [mcve]s. (2) What does this have to do with Ruby? – Nic Mar 29 '17 at 05:09
  • Sorry for the delay ... In my Rails view i've a calendar (https://github.com/excid3/simple_calendar). When i try to print the page the simple calendar does not appear in the print preview. That's a problem born recently. Because, when in the calendar there were few elements, i was able to print the page correctly. – Federico Apr 06 '17 at 11:02

0 Answers0