【问题标题】:Print iframe using jquery inside iframe on iOS and Android在 iOS 和 Android 上的 iframe 中使用 jquery 打印 iframe
【发布时间】:2016-10-23 05:46:30
【问题描述】:

如何在 iOS 和 Android 的 iframe 中使用 jquery 打印 iframe 窗口。我有以下适用于 IE、Chrome 和 Firefox 的代码,但在 Android 上,它似乎正在打印顶部带有 iframe 的整个父窗口。

if (document.queryCommandSupported('print')) {
    // IE and Chrome
    document.execCommand('print', false, null);
} else if((navigator.userAgent.toLowerCase().indexOf("android") > -1) || (navigator.userAgent.toLowerCase().match(/(ipod|iphone|ipad)/))) {
    // Android or iOS
    $('iframe').contentWindow.focus();
    $('iframe').contentWindow.print();
} else {
    // Firefox
    window.print();
} 

我尝试使用 iframe 标记选择 iframe,但它似乎不起作用。请问有什么想法吗?

【问题讨论】:

    标签: jquery ios iframe printing


    【解决方案1】:

    使用$('#iframe').contents(); 仅获取框架的内容。

    【讨论】:

    • 我正在使用 Jack Moore 的颜色框,我尝试了以下方法,但 iPad 上 Safari 中的打印预览显示空白页:$('.cboxIframe').focus(); $('.cboxIframe').contents().print();
    • 框架是否在同一个域中?否则,跨域策略将不允许您访问内容。
    • 是的,它在同一个域中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-03
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    • 2010-12-11
    • 1970-01-01
    相关资源
    最近更新 更多