$(function () {
    // Define the pre-print event
    var beforePrint = function () {
        console.log("Before printing");
    };
    // Define the post-print event
    var afterPrint = function () {
        console.log("After printing");
        app.post('ba.service.CompanyService'.'updateCompany', {
            'companyId': companyId,
            "autoRegStateCode":"40"
        })
            .then(function (res) {}); }// Listen for the window state
    if (window.matchMedia) {
        var mediaQueryList = window.matchMedia('print');

        // Add an event for printing
        mediaQueryList.addListener(function (mql) {
            if (mql.matches) {
                beforePrint();
            } else{ afterPrint(); }}); }// Print the pre-event
    window.onbeforeprint = beforePrint;

    // Post-print events
    window.onafterprint = afterPrint;
    // Perform printing
    $(".print").click(function () {$(".print").hide()
        var newstr = document.getElementById("printPage").innerHTML;
        window.print();
        $(".print").show()
    })
});
Copy the code

Ps: Google calls, before the callback, after the callback, two functions, each will be called twice