I have a app with a doctype. Now I want to print this doctype, but I have to include javascript in the print format. The javascript also calls a custom api method of mine. Unforunately I cannot do this. The print page is always empty. How do I add javascript (outside of jinja2) into my print format and make it print?
I wanted to use js in my custom print format too. I thought of the script tags and tried getting elements that I have created just in tags above. But it returned null. Here is what I tried.
When I tried this format in the preview null was returned in the console. Can somebody help me by explaining what I’m doing wrong? I tried to put in inside the $(document).ready(function(){ }) part but in vain. I actually need to load data into that html table from my child table field. But how come I can’t even access the element?
var mywindow = window.open();
var content = document.getElementById(elem).innerHTML;
mywindow.document.write(content);
mywindow.print();
In the above code, when you click the button “Print Div” , a JavaScript popup window is created and extracted the contents of the HTML div elements to store it in a JavaScript variable. Then the contents of the HTML div elements are written to the popup window and finally the window is printed using the JavaScript print() command.