프로그램 자료/Java Script

Javascript print callback 인쇄 전, 후 이벤트 주기 필요한 영역만 프린트하기

motolies 2014. 10. 16. 17:35

출처 : https://gist.github.com/shaliko/4110822




Cross browser print request detection (IE 5+, Firefox 6+, Chrome 9+, and Safari 5.1+ )




<script type="text/javascript">

    (function () {

        var beforePrint = function () {

            console.log('Functionality to run before printing.');

        };

        var afterPrint = function () {

            console.log('Functionality to run after printing');

        };

 

        if (window.matchMedia) {

            var mediaQueryList = window.matchMedia('print');

            mediaQueryList.addListener(function (mql) {

                if (mql.matches) {

                    beforePrint();

                } else {

                    afterPrint();

                }

            });

        }

 

        window.onbeforeprint = beforePrint;

        window.onafterprint = afterPrint;

    }());

  

    $(funtion(){

window.print();

    }); 

 

</script>