Print Format with Javascript

Hey there,

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?

This has been in Load a Javascript in /print but there is no solution to it.


I think you can place script tags at the end of HTML in your custom print format.

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?

Try print the content of a Div using JavaScript

var mywindow =;
var content = document.getElementById(elem).innerHTML;

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.