Skip to content

Commit

Permalink
case browser incompatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien Peyre committed Dec 18, 2018
1 parent 04a1356 commit 093ec18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default {
onLoadingEnd: null,
onPrintDialogClose: null,
onPdfOpen: null,
onBrowserIncompatible: () => true,
modalMessage: 'Retrieving Document...',
frameId: 'printJS',
htmlData: '',
Expand Down Expand Up @@ -76,6 +77,7 @@ export default {
params.onLoadingEnd = typeof args.onLoadingEnd !== 'undefined' ? args.onLoadingEnd : params.onLoadingEnd
params.onPrintDialogClose = typeof args.onPrintDialogClose !== 'undefined' ? args.onPrintDialogClose : params.onPrintDialogClose
params.onPdfOpen = typeof args.onPdfOpen !== 'undefined' ? args.onPdfOpen : params.onPdfOpen
params.onBrowserIncompatible = typeof args.onBrowserIncompatible !== 'undefined' ? args.onBrowserIncompatible : params.onBrowserIncompatible;
params.modalMessage = typeof args.modalMessage !== 'undefined' ? args.modalMessage : params.modalMessage
params.documentTitle = typeof args.documentTitle !== 'undefined' ? args.documentTitle : params.documentTitle
params.targetStyle = typeof args.targetStyle !== 'undefined' ? args.targetStyle : params.targetStyle
Expand Down Expand Up @@ -147,9 +149,11 @@ export default {
if (Browser.isFirefox() || Browser.isEdge() || Browser.isIE()) {
try {
console.info('PrintJS currently doesn\'t support PDF printing in Firefox, Internet Explorer and Edge.')
let win = window.open(params.fallbackPrintable, '_blank')
win.focus()
if (params.onPdfOpen) params.onPdfOpen()
if (params.onBrowserIncompatible() === true) {
let win = window.open(params.fallbackPrintable, '_blank')
win.focus()
if (params.onPdfOpen) params.onPdfOpen()
}
} catch (e) {
params.onError(e)
} finally {
Expand Down
14 changes: 14 additions & 0 deletions test/manual/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
});
}

function printPdfCompatibleBrowser() {
printJS({
printable: '/test/manual/test.pdf',
type: 'pdf',
onBrowserIncompatible: () => {
alert('Browser incompatible');
return false;
}
});
}

function printHtml() {
printJS({
printable: 'test',
Expand Down Expand Up @@ -140,6 +151,9 @@ <h1>Print.js Test Page</h1>
<button onClick='printPdfWithModalAndCloseCallback();'>
Print PDF with Loading Modal and close callback
</button>
<button onClick='printPdfCompatibleBrowser();'>
Print PDF only on compatible browser
</button>
</p>
<p>
<button onClick='printHtml();'>
Expand Down

0 comments on commit 093ec18

Please sign in to comment.