PrizmDoc Viewer v13.11 Release - Updated
Subscribe to Events
Developer Guide > Viewer > How to Customize the Viewer > Subscribe to Events

Subscribing to ViewerControl Events

The ViewerControl has several events defined in the enumeration PCCViewer.EventType that can be subscribed to using the .on method. The .off method can be used to unsubscribe to previously subscribed events. Event subscription allows you to provide a function[m1]  that is called whenever the event is fired. This method is called a 'handler'. When the event is triggered, the handler is called with one argument, a PCCViewer.Event object that is augmented with properties specific to the event type.

Event subscription should be performed immediately after the ViewerControl is created, or within the ViewerReady event, to ensure that no events are triggered before subscription.

Example
Copy Code
var viewer = new PCCViewer.ViewerControl(viewerElement,
         {
             documentID: viewingSessionId,
             imageHandlerUrl: "../pcc.ashx"
         });
 
viewer.on(PCCViewer.EventType.ViewerReady, viewerReadyHandler);          
 
function viewerReadyHandler(event) {
      alert("The ViewerReady event was fired.);
          // Now Subscribe to the event PCCViewer.EventType.PageChanged
          //exposed by the API
        viewer.on(PCCViewer.EventType.PageChanged, function(event) {
          alert("The current Page is " + event.pageNumber);
});
         //subscribe to other events here… 
}

An enumeration, PCCViewer.EventType, defines event types that are triggered by the ViewerControl. It's acceptable to use this enum or use string literals when subscribing and unsubscribing.