Print window (HTML/PHP)
Author
Discussion

BliarOut

Original Poster:

72,863 posts

269 months

Thursday 20th October 2005
quotequote all
Right, my PHP/MySQL thingumy does most of what I want it to in terms of storing/updating info etc. Now I have to think about getting it to spit bits of paper out.

I want a button that users click and it spits the paper out with the minumum of user interaction.

I'm assuming I want to use a bit of javascript that is attached to an "on open" type event, but what?

Ideally as soon as the print document opens in a new window, I want it to print and then close itself. It's only ever a single page of A4.

What's the best method of achieving this?

NB: It will be a PHP document as it pulls information for a job sheet from the underlying MySQL.


Edit:

Is it really this simple?

script language="JavaScript"
window.print();
/script

So how do I close the window?


>> Edited by BliarOut on Thursday 20th October 13:27

jamieboy

5,929 posts

259 months

Thursday 20th October 2005
quotequote all
I've only done it once, and I used:

onload="window.print();window.close()"

...inside the 'body' tag at the start of the document.

I'm sure someone will be along shortly to tell us both why it's the wrong way to do it, but it seems to work OK.

BliarOut

Original Poster:

72,863 posts

269 months

Thursday 20th October 2005
quotequote all
Eh, there's a post missing Anyway, sorted, I thought it would be more difficult

_dobbo_

14,619 posts

278 months

Thursday 20th October 2005
quotequote all
It was me, I posted totally the wrong answer then deleted it to avoid embarassment...... glad you got it sorted.

BliarOut

Original Poster:

72,863 posts

269 months

Thursday 20th October 2005
quotequote all
_dobbo_ said:
It was me, I posted totally the wrong answer then deleted it to avoid embarassment...... glad you got it sorted.


I nicked the bits that were right

What was that dontPrint thingumy, that looks handy. Is it a standard property or a function?

docevi1

10,430 posts

278 months

Thursday 20th October 2005
quotequote all
is there a way to choose the target printer / configure which trays to use as well?

I'm highly doubtful, but worth asking

_dobbo_

14,619 posts

278 months

Thursday 20th October 2005
quotequote all
BliarOut said:

_dobbo_ said:
It was me, I posted totally the wrong answer then deleted it to avoid embarassment...... glad you got it sorted.



I nicked the bits that were right

What was that dontPrint thingumy, that looks handy. Is it a standard property or a function?


I stole the code straight off another website and made it work on mine - the class thing must have been out of the css for that site - no idea what it does though...

BliarOut

Original Poster:

72,863 posts

269 months

Friday 21st October 2005
quotequote all
Lets you display images on the page that don't appear at print time..... Could save a lot of duplication

slapmatt

1,132 posts

252 months

Friday 21st October 2005
quotequote all
window.print() will open the Print dialog window, same as going File>Print... or pressing Ctrl+P.

There's nothing wrong with it, but I remember back in the mists of time that it used to be IE specific.

jamieboy

5,929 posts

259 months

Friday 21st October 2005
quotequote all
slapmatt said:
window.print() ... used to be IE specific.


maybe - seems to work OK in Firefox 1.0.7