-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It doesn't work on iPhone or iPad #1
Comments
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. |
@n9yty If you manage to resolve the issue for i* devices, please add a pull request with the patch. Thanks for your contribution! |
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. ;) |
@n9yty awesome, thanks for the update. |
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 _print = function (elements) { 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. :) |
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. |
@n9yty Ok. Thanks for your efforts! |
This is really great solution to the old trick as you state in your website, however it still doesn't work on iPhone or iPad(no android to test). Can you explain why or any solution?
The text was updated successfully, but these errors were encountered: