简体   繁体   中英

Problems with javascript print function

I have this javascript code to print html table from a PHP document.

function printReport()
{
    var data = '<input type="button" value="Print this page" onClick="window.print()">';           
    data += '<input type="button" value="Close this page" onClick="window.close()">';
    data += '<table border="0"';
    data += $('#reportTable').html();
    data += '</table>';

    myWindow=window.open('','','scrollbars=yes,resizable=yes,width=500,height=400');
    myWindow.innerWidth = screen.width;
    myWindow.innerHeight = screen.height;
    myWindow.screenX = 0;
    myWindow.screenY = 0;
    myWindow.document.write(data);
    myWindow.focus();
};

It opens the new windows, displays the content right, the close button works fine, however the print button doesnt work.

My printer is working properly, I printed from word or any other app and works fine.

My problem is: the print function window.print() is NOT working.

If anyone could give me a hand, would be appreciated.

Cheers

Change:

data += '<table border="0"';

to

data += '<table border="0">';

and tell us the net result. Tested with simple HTML content within the table. Assuming your .html() call returns valid table data, the window should be printable now.

Working fiddle here: http://jsfiddle.net/aV85r/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM