sarpay
5/21/2014 - 11:49 PM

[jscript] creating a printable version of a div

[jscript] creating a printable version of a div

function printContent() {

    var divHtml;

    divHtml = "<!DOCTYPE html>\n";
    divHtml += "<html>\n";
    divHtml += "<head>\n";
    divHtml += "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/styles.css\">\n";
    divHtml += "</head>";
    divHtml += "<body>";
    divHtml += "<div id=\"result\">\n";
    divHtml += $('#result').html() + "\n";
    divHtml += "</div>\n";
    divHtml += "</body>\n";
    divHtml += "</html>";

    var windowObject = window.open(
        '', 
        'PrintWindow', 
        'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes',
        false);
    windowObject.document.writeln(divHtml);
    windowObject.document.close();
    windowObject.focus();
    windowObject.print();
    setTimeout(function() {
        windowObject.close();
    }, 1000);
    
}