Link to home
Start Free TrialLog in
Avatar of rkarthik29
rkarthik29

asked on

javascript print screen

can we detect using javascript, the pressing of the print screen button, on html web form.
can anyone enlightne me.

Karthik
Avatar of Roonaan
Roonaan
Flag of Netherlands image

googling on 'javascript onprint' lead me to believe you could create two functions in javascript:

function window.onbeforeprint(){
}
function window.onafterprint(){
}

but i cannot test things myself - except for the 'print preview' which seems to work okee-, because I haven't got a printer installed on this pc.

regards

-r-
Avatar of rkarthik29
rkarthik29

ASKER

i meant the printscreen button on ur keyboard.
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This will put 2 buttons on yuor screen.  The 1st is a PRINT and the 2nd is CLOSE THIS WINDOW (I have it in a popup window).

document.write('<form>'

+ '<input type=button name=print value="Print this page" '

+ 'onClick="javascript:window.print()"> '

+ '<input type=button name=close value="Close this page" '

+ 'onClick="javascript:window.close()"></form>');

If you do not want the "close this page", just have this:

document.write('<form>'

+ '<input type=button name=print value="Print this page" '

+ 'onClick="javascript:window.print()"> '

+ '</form>');

This will print the web page it is on.

If you need any additional info, let us know.

Radnor
Radnor,

Please read the question and comments.  The member has alredy indicated that is not what they want.  They are referring to "printsceern", not the print function of the browser.

Cd&