【问题标题】:Pop Up Print is not working in android and ipad弹出打印在 android 和 ipad 中不起作用
【发布时间】:2017-03-08 16:55:14
【问题描述】:

这是我的 jquery 代码:

jQuery('.print_btn').hide();
var contents = document.getElementById("print_page").innerHTML;
var frame1 = document.createElement('iframe');
frame1.name = "frame1";
frame1.style.position = "absolute";
frame1.style.top = "-1000000px";
document.body.appendChild(frame1);
var frameDoc = (frame1.contentWindow) ? frame1.contentWindow : (frame1.contentDocument.document) ? frame1.contentDocument.document : frame1.contentDocument;
frameDoc.document.open();
frameDoc.document.write('<html><head><title></title>');
frameDoc.document.write('</head><body>');
frameDoc.document.write(contents);
frameDoc.document.write('</body></html>');
frameDoc.document.close();
setTimeout(function () {
    frameDoc.focus();
    frameDoc.print();
    document.body.removeChild(frame1);
}, 500);
jQuery('.print_btn').show();
return false;

我在谷歌上搜索,但我没有找到任何解决方案,所以我发布了这个问题。 我有一个带有图像和打印按钮的弹出窗口,我想在单击打印按钮时打印图像。 这在网络浏览器上工作正常意味着在桌面上,但它正在打印整个页面和弹出图像,而在 ipad 上它什么也没打印。

为什么会这样,我不知道请帮帮我。

【问题讨论】:

    标签: javascript jquery html css


    【解决方案1】:

    很遗憾,.print() 在 Android 设备上不受支持。但是,您可以使用 Google 的云打印 API:https://developers.google.com/cloud-print/docs/gadget

    【讨论】:

    • Iphone 或 ipad 怎么样。是的,你的回答很有帮助。
    • 假设您使用的是 iOS 4.2 或更高版本,.print() 应该可以在原生 safari 浏览器中使用。
    • 在我的情况下 window.print() 有效,但 iframe.contentWindow.print() 无效
    猜你喜欢
    • 2015-01-24
    • 1970-01-01
    • 2015-11-08
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    • 1970-01-01
    • 2014-09-16
    • 2015-04-12
    相关资源
    最近更新 更多