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>
Dennis Martinez
  • 6,344
  • 11
  • 50
  • 67

3 Answers3

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

Community
  • 1
  • 1
Jan Pfeifer
  • 2,854
  • 25
  • 35
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 ....

Manse
  • 37,765
  • 10
  • 83
  • 108
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..

Rob
  • 4,927
  • 12
  • 49
  • 54