Giter VIP home page Giter VIP logo

Comments (7)

n9yty avatar n9yty commented on August 12, 2024

I just encounted this same issue, but this is a great solution, there must be a way. Time to dig in I guess and diagnose what the iPad/iPhone doesn't like about it.

from print-elements.

szepeshazi avatar szepeshazi commented on August 12, 2024

@n9yty If you manage to resolve the issue for i* devices, please add a pull request with the patch. Thanks for your contribution!

from print-elements.

n9yty avatar n9yty commented on August 12, 2024

I do find it interesting that if I hook the iPad up to my computer and do remote debugging with Safari, I can put a breakpoint in the javascript on the window.print() line, and if I change the stylesheet from @media print to @media screen the screen on the iPad does properly render just the element.

That means that all the code that walks the tree and assigns the styles is working, and working correctly, it seems that for whatever reason the iPad/iOS is not applying the stylesheet when doing the printing. But yet I have read reports that iOS supposedly has supported @media print for a long time now.

Not sure if that is helpful, if I find anything more I'll come back. Chrome on iOS is no different, but Edge and Firefox on my iPad don't open the print dialog at all, but that is another problem. ;)

from print-elements.

szepeshazi avatar szepeshazi commented on August 12, 2024

@n9yty awesome, thanks for the update.

from print-elements.

n9yty avatar n9yty commented on August 12, 2024

I still can't get it 100%, but the issue seems to be that window.print() does not stop JavaScript execution on iPadOS/iOS, so what happens is that by the time the print dialog is on screen Safari has already removed the classes indicating what to print or not print.

I found that the "afterprint" event is supported, so removing the cleanup code into a separate function that is called as part of that event works "most" of the time. Sometimes, though, the print dialog opens and then "flashes" as it loads the printer options and re-renders the preview as full page. Closing and re-printing seems to work.

So the code I have looks like this: {can't get the code formatting to work here, sorry}

`
var _delayedCleanup = function (elements) {
for (var i = 0; i < elements.length; i++) {
_walkTree(elements[i], _cleanup);
}
}

var _print = function (elements) {
for (var i = 0; i < elements.length; i++) {
_walkTree(elements[i], _attachPrintClasses);
}
window.addEventListener('afterprint', function() { _delayedCleanup(elements) } );
window.print();
};
`

Hopefully that will spark some ideas on maybe a more proper "fix" or workaround for iOS/iPadOS. I'm still digging into JavaScript so am not the best person to deal with edge cases. :)

from print-elements.

n9yty avatar n9yty commented on August 12, 2024

In the end, neither proved reliable as when the print dialog refreshed for any reason the page elements were cleared out. In the end I made a _cleanAll() function that removes all the tags and I call that before setting a new print operation up, and also exposed it so it could be called via a button on the web page for the user to manually reset things. I will fork and send a push request through but it is not a 'fix' but makes changes to operation so you may not want to include it.

from print-elements.

szepeshazi avatar szepeshazi commented on August 12, 2024

@n9yty Ok. Thanks for your efforts!

from print-elements.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.