Javascript – How to make window.print pop up a print dialog with Preview

javascriptprinting

I tried to create a simple HTML page as below

<html>
    <a href="javascript:window.print();">Print this page</a>
    <div>
        something 
        something
    </div>
</html>

After clicking the "Print this page", the pop-up print dialog is quite simple. There is no preview in the dialog.

In Google Calendar, user can print calendar. In "calendar print preview" window, clicking "Print" will pop up print dialog. The print dialog has a preview of the calendar view to be printed. I'm wondering how to call out such print dialog with Javascript.

In my knowledge, Javascript/DOM has only one API "window.print" about printing. Is there any other way to customize print?

Best Answer

The print preview that Google Calendar uses are created as an image on the server and then shown to the user.

Here is a related question: JavaScript print preview

If you are OK with a solution that only works in IE, this question might help you out: How can Print Preview be called from Javascript?

I think this is the way to go, for a cross-browser solution:

http://www.alistapart.com/articles/printtopreview/