簡體   English   中英

Javascript:window.print 的問題

[英]Javascript: Issue with window.print

在最近的瀏覽器更新中,(firefox 95+)發生了一些奇怪的事情。

設想:

- user clicks the print button in main page
- user will be redirected to a new page (print page)
- when the page fully loaded, the window.print() function executes
- when the print dialog dismissed, user will be redirected to main page

例如,我寫了這個 html 代碼:

<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
test
<script language="javascript">
    window.print();
    console.log('1');
</script>
</body>
</html>

本頁所述, window.print()方法將在打印對話框打開時阻塞。 它是真的。 除非在那之后你有更多的腳本行。

在這里打開了一個問題,但對我來說這個問題似乎沒有解決。

如果你粘貼

window.print();
console.log('1');

直接進入瀏覽器控制台,它可以按預期工作。

有什么建議嗎?

這適用於我當前的 Safari 和 Chrome。 控制台日志在打印對話框關閉后執行。

 window.onafterprint = event => { console.log('after print'); }; window.print();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM