Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript set print stylesheet

How would I modify the style of an object for the print stylesheet? I'm using jQuery, if that's of any help.

I basically want to set a css property of an object, but have that property apply for print only, not screen. e.g. $('#myobject').css('background','white','print');

like image 777
Leticia Meyer Avatar asked Oct 24 '25 20:10

Leticia Meyer


2 Answers

This question is a little vague, so I'm not sure if I'm following what you're trying to do. Are you trying to dynamically modify the style of an object for print?

If so, you can try adding styles to the head, like the following:

$('head').append('<style type="text/css" media="print">Whatever styles</style>');
like image 134
Paul Sham Avatar answered Oct 26 '25 12:10

Paul Sham


You are going to need to add a CSSStyleSheet to document.styleSheets and set the media type to print. https://developer.mozilla.org/en/DOM/stylesheet

like image 37
Haochi Avatar answered Oct 26 '25 10:10

Haochi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!