Appearance
Viewer messages
The viewer emits messages triggered by user actions, allowing you to customise the experience that your site provides in response.
The viewer emits messages to the parent window using the window.postMessage API. You can listen for these messages by adding an event listener to the window
object.
Messages
Message | Description |
---|---|
scpDialogPrintShow | Print dialog was displayed |
scpDialogPrintApprove | User launched browser print dialog |
scpDialogPrintDeny | User cancelled printing |
scpOnBeforePrint | Triggered before the browser displays its print dialog |
scpOnAfterPrint | Triggered after the browser print dialog has been closed |
scpOnDownloadClick | Triggered when the download button is clicked |
Examples
Listening for messages
This example demonstrates how to listen for messages from the viewer. On receipt of a message, a log message is written to the console.
js
const Messages = {
DIALOG_PRINT_SHOW: "scpDialogPrintShow",
DIALOG_PRINT_APPROVE: "scpDialogPrintApprove",
DIALOG_PRINT_DENY: "scpDialogPrintDeny",
ON_BEFORE_PRINT: "scpOnBeforePrint",
ON_AFTER_PRINT: "scpOnAfterPrint",
ON_DOWNLOAD_CLICK: "scpOnDownloadClick",
};
// Add event listener for message event
window.addEventListener(
"message",
(event) => {
switch (event.data) {
case Messages.DIALOG_PRINT_SHOW:
console.log("SCP print dialog shown");
break;
case Messages.DIALOG_PRINT_APPROVE:
console.log("SCP print dialog approved");
break;
default:
console.warn(`Unhandled message ${event.data}`);
break;
}
},
false,
);