简体   繁体   English

打印媒体查询无法在iOS上运行(chrome,safari,mozilla)

[英]print media query not working on iOS(chrome, safari, mozilla)

I'm trying to figure why the @media print doesn't seem to work on the iOS, on android the functionality works fine. 我试图弄清楚为什么@media print似乎不适用于iOS,在Android上功能正常。 Basically I've made a functionality to hide the contents that aren't part of the print 基本上我已经创建了一个隐藏不属于打印内容的功能

body.printing *{display : none}

and only display the contents that will be printed 并且仅显示将要打印的内容

body.printing .print-me, body.printing .print-me > div{display : block} . body.printing .print-me, body.printing .print-me > div{display : block}

$('.print-modal').on('click', function() {
    $('body').addClass('printing');
    window.print();
   $("body").removeClass("printing");
})
@media print {
    /* Hide everything in the body when printing... */
    body.printing * { display: none; }
    /* ...except our special div. */
    body.printing .print-me, body.printing .print-me > div { display: block; }
}

@media screen {
    /* Hide the special layer from the screen. */
    .print-me { display: none; }
}

Maybe the issue is, you are adding a class printing and removing the same class immediately. 也许问题是,您正在添加类printing并立即删除相同的类。 That's could be the reason. 这可能是原因。

Try changing the logic. 尝试更改逻辑。 You don't need to add a class for printing. 您无需为打印添加类。 Instead use print media query @media print to handle print logic. 而是使用打印介质查询@media print来处理打印逻辑。

$('.print-modal').on('click', function() {
    window.print();
})

@media print {
    /* Hide everything in the body when printing... */
    body * { display: none; }
    /* ...except our special div. */
    body .print-me, body .print-me > div { display: block; }
}

@media screen {
    /* Hide the special layer from the screen. */
    .print-me { display: none; }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jquery在chrome,mozilla和IE中工作但不在safari中工作 - jquery working in chrome, mozilla and IE but not in safari DOM方法无法在Chrome,safari,mozilla中运行,在IE *中可以正常工作 - DOM methods not working in Chrome, safari, mozilla, working fine in IE* 视频无法在Safari(从Windows)中使用,但可以在Mozilla和Chrome中使用 - Video is no working in safari(from Windows) but working in Mozilla and chrome Javascript(JS)应用程序可在Chrome上运行,但不能在mozilla firefox / safari上运行 - Javascript (JS) application working on Chrome but not on mozilla firefox/safari 此jQuery代码在Mozilla上运行良好,但在Chrome,Opera和Safari上运行不佳 - This jQuery code is working great on Mozilla, but not on Chrome, Opera, Safari 功能在IE8中运行良好,但在Chrome,Mozilla,safari中没有 - Function working fine in IE8 but not in Chrome, Mozilla, safari jQuery表单验证可在Mozilla和Internet Explorer中使用,但不能在Chrome或Safari中使用 - jQuery Form Validation Working in Mozilla and Internet Explorer, but not in Chrome or Safari scrollIntoView() 在 IOS safari 和 chrome 上不起作用? - scrollIntoView() not working on IOS safari and chrome? 媒体查询无法在Safari中工作,但在IE,Firefox和Chrome中 - Media queries not working in Safari but in IE, Firefox and Chrome window.print()在chrome中工作,但在safari中不工作 - window.print() working in chrome but not working in safari
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM