Skip to content

Commit 5c05711

Browse files
committed
Fixed reference from popup to popupOrIframe.
jQuerified the iframe creation. Focus current window before writing html to iframe. Fixes issue I encountered where only 1st attempt to print would succeed, others would print entire page. Works great now!
1 parent 35af95b commit 5c05711

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

jQuery.printElement/jquery.printElement.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,17 @@
5353

5454
if (opts.printMode.toLowerCase() == 'popup') {
5555
popupOrIframe = window.open('', 'printElementWindow', 'width=650,height=440,scrollbars=yes');
56-
documentToWriteTo = popup.document;
56+
documentToWriteTo = popupOrIframe.document;
5757
}
5858
else {
5959
var printElementID = "printElement_" + (Math.random() * 99999).toString();
60-
iframe = document.createElement('IFRAME');
61-
$(iframe).attr({ style: opts.iframeElementOptions.styleToAdd,
60+
popupOrIframe = $('<iframe />').attr({ style: opts.iframeElementOptions.styleToAdd,
6261
id: printElementID,
6362
className: opts.iframeElementOptions.classNameToAdd
64-
});
65-
document.body.appendChild(iframe);
66-
documentToWriteTo = iframe.contentWindow.document;
67-
var iframe = document.frames ? document.frames[printElementID] : document.getElementById(printElementID);
68-
popupOrIframe = iframe.contentWindow || iframe;
63+
}).appendTo('body')[0].contentWindow;
64+
documentToWriteTo = popupOrIframe.document;
6965
}
66+
window.focus();
7067
documentToWriteTo.open();
7168
documentToWriteTo.write(html);
7269
documentToWriteTo.close();

0 commit comments

Comments
 (0)