Kyle Vancamp Kyle Vancamp - 6 months ago 10
Javascript Question

period removed from filename when printing with jquery

I've been tasked with coming up with a solution for dynamically printing a specific part of the page in an existing application. I'm getting information by finding certain sections of the page based on class tags and then printing that section with the following.

function PrintElem(element,title) {
var data = $(element).html();
var mywindow = window.open('', title, 'height=800,width=1000');
mywindow.document.write('<html><head><title>' + title + '</title>');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');

mywindow.print();
mywindow.close();
return true;
}


The problem occurs with the title variable. The title is used for the window thats opened and the printed file name and is based on a company document type, customer, part number and part number revision. On a part I've been testing the title variable shows as RTR_COMPANY_3900801597.1_A the problem occurs when its printed. Once the print dialog opens it drops the .1_A (in chrome, edge, IE, firefox) and so far I haven't found or thought of a way to get around this. Other thoughts are that it must be able to work in Chrome (used company wide). Any thoughts?

Answer

If I get you right, you're using a dot in a way that your SO could get confused with a file extension (.1_A). Can you try setting a file extension after the name like

mywindow.document.write('<html><head><title>' + title + '.pdf</title>');

Aso, check this post