printThis.js
function attachOnBeforePrintEvent($iframe, beforePrintHandler) {
                var win = $iframe.get(0);
                win = win.contentWindow || win.contentDocument || win;

                if (typeof beforePrintHandler === "function") {
                    if ('matchMedia' in win) {
                        win.matchMedia('print').addListener(function(mql) {
                            if(mql.matches)  beforePrintHandler();
                        });
                    } else {
                        win.onbeforeprint = beforePrintHandler;
                    }
                }
            }
function attachOnBeforePrintEvent($iframe, beforePrintHandler) {
                var win = $iframe.get(0);
                win = win.contentWindow || win.contentDocument || win;

                if (typeof beforePrintHandler === "function") {
                    if ('matchMedia' in win) {
                        win.matchMedia('print').addListener(function(mql) {
                            if(mql.matches)  beforePrintHandler();
                        });
                    } else {
                        win.onbeforeprint = beforePrintHandler;
                    }
                }
            }
function attachOnBeforePrintEvent ( $iframe , beforePrintHandler ) { var win = $iframe . get ( 0 ) ; win = win . contentWindow || win . contentDocument || win ; if ( typeof beforePrintHandler === "function" ) { if ( 'matchMedia' in win ) { win . matchMedia ( 'print' ) . addListener ( function ( mql ) { if ( mql . matches ) beforePrintHandler ( ) ; } ) ; } else { win . onbeforeprint = beforePrintHandler ; } } }
attach event handler function to beforePrint event
attach event handler function to beforePrint event