iOS 8 Safari print redirect doesn't stop javascript execution

前端 未结 1 1447
长发绾君心
长发绾君心 2021-02-08 23:14

I have the need to provide the ability to print a label on successful save and after the print redirect to a search page. This works in chrome, firefox, ie, iOS 6/7 safari, etc.

1条回答
  •  你的背包
    2021-02-08 23:37

    You can use window.matchMedia (caniuse link), combined with window.onbeforeprint and window.onafterprint (for earlier IE support). A good reference for using matchMedia can be found here and here.

    To satisfy using matchMedia with iOS, use nested events. First, listen for the media type to change to print. Then, inside that callback, listen for the media to change back to screen.

    if (window.matchMedia) {
        var printQuery = window.matchMedia('print');
        printQuery.addListener(function() {
            var screenQuery = window.matchMedia('screen');
            screenQuery.addListener(function() {
                //actions after print dialog close here
            });
        });
    }
    

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