Q? about javascript function

mairving's picture

They have: 2,256 posts

Joined: Feb 2001

I built a js function. What it does is that upon form submission, someone clicks on the link, it then opens a new page, brings up the print page and when it is printed or cancelled it closes the page. Any ideas on how well this will work or potential problems. Here is the code:

<script language="JavaScript" type="text/javascript">
<!--
function printit() {
    if (window.print) {window.print();}
self.close();
}
-->
&lt;/script&gt;
<body onLoad="printit();">
'

Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Seems pretty straighforward. what happens if window.print isn't available?

mairving's picture

They have: 2,256 posts

Joined: Feb 2001

Usually I have 3 pages with every form. The form, a display page that displays what was just entered and a print page. If the print page doesn't work, then they can print it from the display page, just doesn't look as nice. So it is still functional without it.

Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

You might want to have it so the window only pops up if the window.print() is available.

dk01's picture

He has: 516 posts

Joined: Mar 2002

Or have it so that the "Print This Page" link is only showing if window.print is available.
-dk

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

ah, yes, that's a lovely solution.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.