[英]Window.print() not working in ipad chrome in popup window[window.open()]
Below is my piece of code that work's in all the browser in all the OS, except ipad chrome.下面是我的一段代码,它可以在所有操作系统的所有浏览器中运行,除了 ipad chrome。 Help me out here.
帮帮我。
<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>
Here Im trying to open my content using window.open()
then print them using window.print()
.在这里,我尝试使用
window.open()
打开我的内容,然后使用window.print()
打印它们。 That's all.就这样。 jsfiddle
jsfiddle
This link also not working in ipad chrome.此链接在 ipad chrome 中也不起作用。 Print
打印
Try this code, if it not works another solution is to use a third-party printing service like this: http://www.printfriendly.com 尝试使用此代码,如果它不起作用,另一解决方案是使用像这样的第三方打印服务: http : //www.printfriendly.com
function goPrint(){ window.print(); if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1) { window.location.reload(); } }
You are using a backtick character `
in this line: 您在此行中使用反引号
`
wnd.document.write(`<div class="print-header"><button title="Print" onclick="window.print()">Print</button></div>`);
This is a Templated literal and might not be supported. 这是一个模板化文字 ,可能不受支持。 Try replacing it with a single quote:
尝试用单引号替换它:
wnd.document.write('<div class="print-header"><button title="Print" onclick="window.print()">Print</button></div>');
This is an issue with Chrome on iOS.这是 iOS 上的 Chrome 的一个问题。 Because of Apple's policy on third party browsers, Chrome is actually just a WebView component.
由于 Apple 对第三方浏览器的政策,Chrome 实际上只是一个 WebView 组件。 Printing is currently not supported.
当前不支持打印。 As far as I am aware, there is currently no workaround for this issue.
据我所知,目前没有解决此问题的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.