Window.print() 在弹出窗口 [window.open()] 中的 ipad chrome 中不起作用



下面是我的一段代码,可以在所有操作系统的所有浏览器中工作,除了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()打印它们。就这样。斯菲德尔

此链接在 ipad chrome 中也不起作用。 打印

这是 iOS 上的 Chrome 的问题。由于苹果对第三方浏览器的政策,Chrome实际上只是一个WebView组件。当前不支持打印。据我所知,此问题目前没有解决方法。

试试这段代码,如果它不起作用,另一种解决方案是使用第三方打印服务,如下所示: 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>');

最新更新