找出何时打印完成 Jquery

Imp*_*uck 2 html javascript jquery

有没有办法使用 JQuery 找出打印何时结束。我不想找到打印窗口何时关闭,而是何时完成实际打印。我的问题是,当用户在我的网络应用程序上打印一个页面并从页面快速导航时,打印被切断并且没有给出整个打印结果。(我在想是否可以阻止 UI 直到实际打印结束,它将解决问题)。

Ant*_*ony 5

您可以结合使用window.onafterprint(IE 5+ 和 FireFox 6+window.matchMedia支持)和使用(Chrome 9+ 和 Safari 5.1+ 支持)。不幸的是,Opera 也不支持。这是一篇详细介绍该方法的文章。

这是防止链接失效的代码:

(function() {
    var beforePrint = function() {
        console.log('Functionality to run before printing.');
    };
    var afterPrint = function() {
        console.log('Functionality to run after printing');
    };

    // supported by Chrome 9+ and Safari 5.1+
    if (window.matchMedia) {
        var mediaQueryList = window.matchMedia('print');
        mediaQueryList.addListener(function(mql) {
            if (mql.matches) {
                beforePrint();
            } else {
                afterPrint();
            }
        });
    }

    // supported by IE 5+ and FireFox 6+
    window.onbeforeprint = beforePrint;
    window.onafterprint = afterPrint;
}());
Run Code Online (Sandbox Code Playgroud)