Listening to WebViewer UI events
The UI namespace contains APIs and objects related to the default WebViewer UI. It can also trigger events related to the UI to detect when users interact with the UI. For example, it could be used to open the notes panel when the tool group changes or when certain thumbnails are selected.
Document Load Error event
The loaderror event was first introduced in the loading guide. This event is triggered from the UI due to the WebViewer Core maintaining a level of customizability on document load error handling via the onError option of the createDocument API.
WebViewer({
initialDoc: 'https://myserver.com/myfile.pdf'
}, document.getElementById('viewer'))
.then(instance => {
instance.UI.addEventListener('loaderror', err => {
instance.UI.displayErrorMessage(err.detail.message);
});
});WebViewer({
initialDoc: 'https://myserver.com/myfile.pdf'
}, document.getElementById('viewer'))
.then(instance => {
const { iframeWindow } = instance;
// loaderror is only available through the iframe for WebViewer 7 and below
iframeWindow.addEventListener('loaderror', err => {
instance.UI.displayErrorMessage(err.detail.message);
});
});Toolbar events
When the user changes toolbar groups in the header, a toolbarGroupChanged event will trigger to indicate the new group.
WebViewer({
initialDoc: 'https://myserver.com/myfile.pdf'
}, document.getElementById('viewer'))
.then(instance => {
const { ToolbarGroup } = instance.UI;
instance.UI.addEventListener('toolbarGroupChanged', e => {
if (e.detail === ToolbarGroup.ANNOTATE) {
instance.UI.openElements(['notesPanel']);
}
});
});WebViewer({
initialDoc: 'https://myserver.com/myfile.pdf'
}, document.getElementById('viewer'))
.then(instance => {
instance.on('toolbarGroupChanged', e => {
if (e.detail === 'toolbarGroup-Annotate') {
instance.openElements(['notesPanel']);
}
});
});Thumbnail events
If you want to react to interactions with the thumbnails in the thumbnails panel, WebViewer also provides a set of events that can be listened to.
Last updated
Was this helpful?