Kyle Vancamp Kyle Vancamp - 1 year ago 93
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 ='', title, 'height=800,width=1000');
mywindow.document.write('<html><head><title>' + title + '</title>');
mywindow.document.write('</head><body >');

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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download