Skip to content

Commit

Permalink
[bugfix] enables printing on mobile Chrome
Browse files Browse the repository at this point in the history
Implements fix suggested here:
jasonday#152 (comment)
  • Loading branch information
evanb2 committed Dec 18, 2019
1 parent 0aa7434 commit 5927116
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions printThis.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,10 @@
attachOnBeforePrintEvent($iframe, opt.beforePrintEvent);

setTimeout(function() {
if ($iframe.hasClass("MSIE")) {
// check if the iframe was created with the ugly hack
// and perform another ugly hack out of neccessity
window.frames["printIframe"].focus();
$head.append("<script> window.print(); </s" + "cript>");
} else {
// proper method
if (document.queryCommandSupported("print")) {
$iframe[0].contentWindow.document.execCommand("print", false, null);
} else {
$iframe[0].contentWindow.focus();
$iframe[0].contentWindow.print();
}
}
// check if the iframe was created with the ugly hack
// and perform another ugly hack out of neccessity
window.frames["printIframe"].focus();
$head.append("<script> window.print(); </script>");

// remove iframe after print
if (!opt.debug) {
Expand Down

1 comment on commit 5927116

@guptanisha
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evanb2 does this work for u on iPad, for me, it doesn't work.

Appreciate any help!!

Please sign in to comment.