Mike in Coloma
Mike in Coloma

Reputation: 94

Google Chrome Print event capture after selecting Print from menu

I have successfully captured the Ctrl+P event using the following jQuery, but the same code is not executed when you select "Print" from the menu, or by right clicking the page and selecting "Print". Both of these menu's show the shortcut "Ctrl+P" as a hint next to them, but apparently Chrome is not actually triggering the keys.

    $(document).bind("keydown", function (e) {
        if (e.ctrlKey && e.keyCode == 80) {
            printReport("#jsGrid");
            return false;
        }
        return true;
    });

Is there a way to capture the other print events?

Using Google Chrome Version 63.0.3239.132

Upvotes: 1

Views: 520

Answers (1)

Rob M.
Rob M.

Reputation: 36511

You aren't going to be able to intercept a user printing from the Chrome menu, at least not from a webpage. You might be able to accomplish this with a chrome extension using the onPrintRequested method. If you are trying to prevent users from printing your page contents, you might try using CSS:

@media print {
   body { display: none !important; }
}

Upvotes: 1

Related Questions