Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. \This is the original that loads the contents of the first .printableArea.
  2. \Changing the code to [1] instead of [0] gives the contents of the second .printableArea
  3.  
  4. <input type="button" align="centre" onclick="printDiv('printableArea')"
  5. value="Print Page" />
  6. <script>
  7. function printDiv(divName) {
  8. var printContents = document.getElementsByClassName(divName)
  9. [0].innerHTML;
  10. var originalContents = document.body.innerHTML;
  11.  
  12. document.body.innerHTML = printContents;
  13.  
  14. window.print();
  15.  
  16. document.body.innerHTML = originalContents;
  17. }
  18. </script>
  19.  
  20. \This also yields a result if I change to using an id instead of class.
  21.  
  22. <input type="button" align="centre" onclick="printDiv('printableArea')"
  23. value="Print Page" />
  24. <script>
  25. function printDiv(divName) {
  26. var printContents = document.getElementById(divName).innerHTML;
  27. var originalContents = document.body.innerHTML;
  28.  
  29. document.body.innerHTML = printContents;
  30.  
  31. window.print();
  32.  
  33. document.body.innerHTML = originalContents;
  34. }
  35. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement