Firefox:window.print()阻止window.history.back()函数

问题描述 投票:0回答:1

使用window.location.back()后想返回window.print()时出现问题。

当我单击“打印”按钮时,我被重定向到带有要打印文档的新页面,并且出现打印弹出窗口。在Chrome和IE上,当我们单击弹出窗口中的打印时,会触发window.location.back(),但在Firefox中不会触发...

timeout(function () {
   window.print()
   window.history.back();
}, 500);

我已经尝试了一些可能的解决方案,例如window.onafterprintwindow.onbeforeprint事件,window.location.go(-1),但在Firefox上均不起作用。

此外,如果我删除window.print()行,则window.location.back()可以正常工作。

我没有其他解决方案,您能帮我吗?

firefox printing block history back
1个回答
0
投票

您确定不表示setTimeout吗?

使用Firefox,并使用以下html代码:

<!DOCTYPE html>
<html>
<head>
    <script>
        setTimeout(function(){
            window.print();
            window.history.back();
        }, 500);
    </script>
</head>
<body>
    <pre>Nothing here</pre>
</body>
</html>

似乎工作正常。

加载后500毫秒,将显示打印对话框,然后返回历史记录。

© www.soinside.com 2019 - 2024. All rights reserved.