DocuVieware Reference Guide
Reference Guides > JavaScript API > Events > RegisterOnAnnotationSelectedStateChanged

This function allows you trigger a function of your own when an annotation has been selected or unselected.

RegisterOnAnnotationSelectedStateChanged: function (docuViewareID, callback)


The identifier for the DocuVieware™ instance.
The function you want to execute on event.
The callback provides an argument having a prototype { id, state}.
- id specifies the annotation unique id that can be retrieved from the server side using the Guid property of the annotation class.
- state is a boolean that specifies the selected state of the annotation.

Return Value

1 if error.

Example of usage

This JavaScript makes sure the DocuVieware control is properly loaded and initialized and then subscribes to the event on load to display the corresponding annotation id and page in the console.

function RegisterOnAnnotationSelectedStateChangedOnDocuViewareAPIReady() {
   if (typeof DocuViewareAPI !== "undefined" && DocuViewareAPI.IsInitialized("DocuVieware1")) {
      DocuViewareAPI.RegisterOnAnnotationSelectedStateChanged("DocuVieware1", function (annot) {
   else {
      setTimeout(function () { RegisterOnAnnotationSelectedStateChangedOnDocuViewareAPIReady() }, 10);
window.onload = function () {