1

I need to only use a piece of javascript when the print button is clicked, is there a way to do this?

EDIT: A browser print button, i was thinking something like this:

<script type="text/javascript" src="path" media="print"></script>
2
  • do you mean the browser print button? Commented Oct 11, 2011 at 12:48
  • 3
    This appears to make no sense whatsoever. Commented Oct 11, 2011 at 12:50

3 Answers 3

2

There is only a partial support from browsers for that. Consider using special CSS stylesheet for print version of the page. For more details look at this question (there are links to several others): execute javascript when printing page

Sign up to request clarification or add additional context in comments.

Comments

1

Some browsers (Firefox and IE) have events onBeforePrint onAfterPrint ...

https://developer.mozilla.org/en/Printing#Detecting_print_requests

Failing that use a "Press this to print" button and perform what you want from there ....

Comments

0

I think you mean this: JQuery:

$('#btnprint').click(function(){
     //Your JS code goes here
});

Watch out with postbacks!

Im not sure wether u mean the browsers print button or just a custom one, the code above is for your own custom one..

1 Comment

I see what you did there :p

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.