【发布时间】:2018-08-29 12:18:01
【问题描述】:
下面是我的一段代码,它可以在所有操作系统的所有浏览器中运行,除了 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 中也不起作用。 Print
【问题讨论】:
-
document.write 不像构建字符串。如果您没有包含结束标签,则会自动添加它们。所以构建字符串和document.write一次
-
我已经尝试过你的答案,它没有,工作。当我们使用多个 document.write() 时,浏览器并不介意。
标签: javascript html