Back to Top
The nuts and bolts for
Creative web development

Auto Window Print

Q

How can i initialize the print function in JavaScript for a printable page, so that the user doesn't need to click a print-button ?

A

Just put this little script in your page and it will initialize the print pop-up automatically.

<script>
if (window.self) window.print();
</script>

Marcellino Bommezijn

Marcellino BommezijnMarcellino Bommezijn is one of the managers at dmxzone.com. He is a contributor on the tutorials section.

Owner of Senzes Media (http://www.activecontent.nl) which provides professional services and web applications for mid-sized companies.

ActiveContent CMS is the ASP.NET Content Management solution that is used for building professional and rich-featured websites.

See All Postings From Marcellino Bommezijn >>

Share this Article

Comments

RE: Ironic

Hi Chris.
I was looking for a script for printing a html page automatickly in landscape.
And My question for u is, do u know the script?
If so, could u please post it here.

Best,
Andy

Print after page is loaded

It seems there is no way to just dump something to the printer without going through the print dialogue box.

If you want to print the whole page, putting the script at the bottom is not the ideal way to do it as anything not loaded will not print.

Better is <body onLoad="self.print()">   I think we all know the use of onLoad...

RE: RE: Print In Landscape

Does anyone know how to use the landscape orientation for the print() function?

RE: Print In Landscape

See all 11 Comments