[英]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.