[英]Window.print() not working in ipad chrome in popup window[window.open()]
下面是我的一段代碼,它可以在所有操作系統的所有瀏覽器中運行,除了 ipad chrome。 幫幫我。
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<script>
function myprint() {
const wnd = window.open('about:blank', '', '_blank, alwaysRaised=yes');
wnd.document.write('<html><head><title></title>');
wnd.document.write('</head><body>');
wnd.document.write('<div>JavaScript often abbreviated as JS, is a high-level, interpreted programming language. It is a language which is also characterized as dynamic, weakly typed, prototype-based and multi-paradigm.</div>');
wnd.document.write('<div class="print-header"><button title="Print" onclick="window.print()">Print</button></div>');
wnd.document.write('</body></html>');
wnd.document.close();
}
</script>
<body>
<button onclick="myprint()">popup</button>
</body>
</html>
在這里,我嘗試使用window.open()
打開我的內容,然后使用window.print()
打印它們。 就這樣。 jsfiddle
此鏈接在 ipad chrome 中也不起作用。 打印
嘗試使用此代碼,如果它不起作用,另一解決方案是使用像這樣的第三方打印服務: http : //www.printfriendly.com
function goPrint(){ window.print(); if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1) { window.location.reload(); } }
您在此行中使用反引號`
wnd.document.write(`<div class="print-header"><button title="Print" onclick="window.print()">Print</button></div>`);
這是一個模板化文字 ,可能不受支持。 嘗試用單引號替換它:
wnd.document.write('<div class="print-header"><button title="Print" onclick="window.print()">Print</button></div>');
這是 iOS 上的 Chrome 的一個問題。 由於 Apple 對第三方瀏覽器的政策,Chrome 實際上只是一個 WebView 組件。 當前不支持打印。 據我所知,目前沒有解決此問題的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.