Skip to content

Auto-print a page in Apex

April 8, 2010

My web site accepts applications for a sports team, and the last step is the applicant needs to print out a form to be signed. To make things as simple as possible, I want this form to send itself to their printer as soon as they open it. Now, I’m not a javascript expert; but instead of googling for the code, I stole it by doing a View Source on Google Mail’s print feature.

To get any apex page to print when it is opened, all you need to do is add two bits to the page definition:

HTML Header

<script>
function Print(){document.body.offsetHeight;window.print()}
</script>

Page HTML Body Attribute

onload="Print()"

Isn't javascript easy? I'm not sure what the "document.body.offsetHeight" is all about but I suspect it's something to do with waiting for the whole page to load and render before the print starts.

About these ads

From → APEX

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 180 other followers

%d bloggers like this: