no border on HTML table when printing

I think this other SO question, How to print inline CSS styles?, might hold the answer to your question.

Another thing to try is setting your stylesheet using the standard <link rel="stylesheet" href="stylefile.css" type="text/css" media="print" > syntax so you specify one or more media targets (just separate them with a comma).


Try window.print() instead of printDiv() because you're not loading CSS.

or

updating your CSS to this

table {
    border: solid #000 !important;
    border-width: 1px 0 0 1px !important;
}
th, td {
    border: solid #000 !important;
    border-width: 0 1px 1px 0 !important;
}

or to this

@media print {
    table {
        border: solid #000 !important;
        border-width: 1px 0 0 1px !important;
    }
    th, td {
        border: solid #000 !important;
        border-width: 0 1px 1px 0 !important;
    }
}

As the table is being copied to a new window, your CSS is not being retained. You can get around this by passing some relevant CSS across to the new window in your document.write() method. You also need to provide a small amount of padding to introduce the borders. See the following JSFiddle showing this in action: http://jsfiddle.net/826Zm/3/

function printDiv() {
    var divToPrint = document.getElementById('table');
    var htmlToPrint = '' +
        '<style type="text/css">' +
        'table th, table td {' +
        'border:1px solid #000;' +
        'padding:0.5em;' +
        '}' +
        '</style>';
    htmlToPrint += divToPrint.outerHTML;
    newWin = window.open("");
    newWin.document.write(htmlToPrint);
    newWin.print();
    newWin.close();
}