code_junkie

How can I customise the browser's output for print/print preview?

Nov 11th, 2011
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style id="styles" type="text/css">
  4. @media print { .noprint { display:none; } }
  5. </style>
  6. <script type="text/javascript">
  7. var x = Math.random();
  8.  
  9. if (x > .5) {
  10. var style = document.createElement('style');
  11. style.type = 'text/css';
  12. style.innerHTML = '@media print { .maybe_noprint { display:none; } }';
  13. document.getElementsByTagName('head')[0].appendChild(style);
  14. }
  15. </script>
  16. </head>
  17. <body>
  18. <div class="noprint">This will never print.</div>
  19. <span class="maybe_noprint">This may print depending on the value of x.</span>
  20. </body>
  21. </html>
  22.  
  23. <div id='div19' class='noprint'>
  24. ...
  25. </div>
  26.  
  27. .noprint {
  28. display: none;
  29. }
  30.  
  31. document.getElementById('div19').className='noprint';
Add Comment
Please, Sign In to add comment