How to detect the printed status or canceled status in web browser using javascript?

前端 未结 1 1616
长发绾君心
长发绾君心 2021-01-29 09:32

I am just detecting the printed status in web browser. As you can see , browser support the status as cancel or print button. For seeing if user clicked cancel, print button, I

1条回答
  •  时光取名叫无心
    2021-01-29 10:18

    window.print() doesn't return any value.

    I don't think there's a way to know if the user clicked Save or Cancel. It's more of your operating system's job to watch what's going on in there. There're, however, two event handlers

    • window.onbeforeprint and
    • window.onafterprint.

    Code Snippet

    window.onbeforeprint = function() {
        console.log('This will be called before the user prints.');
    };
    
    window.onafterprint = function() {
        console.log('This will be called after the user prints');   
    };
    

    Take a look here

    0 讨论(0)
提交回复
热议问题