Guest User

Untitled

a guest
Mar 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. console.log('running');
  2.  
  3. var onbeforeprintAvailable = false;
  4.  
  5. if ('onbeforeprint' in window) {
  6. window.addEventListener('beforeprint', function () {
  7. console.log('print before (onbefore)');
  8. onbeforeprintAvailable = true;
  9. }, true);
  10. } else {
  11. window.matchMedia('print').addListener(function (event, media) {
  12. console.log('print before (matchmedia)');
  13. console.log(navigator.userAgent.indexOf('Safari'));
  14. onbeforeprintAvailable = true;
  15. console.log(onbeforeprintAvailable);
  16. });
  17. }
  18.  
  19.  
  20. window.addEventListener('afterprint', function (event) {
  21. if (!onbeforeprintAvailable) {
  22. console.log('print after');
  23. }
  24. }, true);
Add Comment
Please, Sign In to add comment