Executing function before page gets to window.print()

前端 未结 4 898
慢半拍i
慢半拍i 2020-12-16 03:19

I have a page that calls window.print(); at the bottom of the page. I have no way of accessing the code around window.print(); Its generated by the server and I can\'t tou

4条回答
  •  生来不讨喜
    2020-12-16 03:58

    "Basically because of IE I need to..."

    If you only need support for IE, see the onbeforeprint event.

    window.onbeforeprint = function () {
        // some code    
    }
    

    The benefit here is that the code will not run in browsers that don't support onbeforeprint, which is pretty much every browser except IE.

提交回复
热议问题