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

This function allows you to trigger a function of your own when text has been selected on the displayed document.

RegisterOnTextSelected: function (docuViewareID, callback)


The identifier for the DocuVieware™ instance.
The function you want to execute on event.
It provides an array of objects containing all the selected text areas with the following prototype: { pageNo, coordinates: { top, left, height, width } }.
The measurement unit for the coordinates is inches relative to the document page.

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.

function RegisterOnTextSelectedOnDocuViewareAPIReady() {
    if (typeof DocuViewareAPI !== "undefined" && DocuViewareAPI.IsInitialized("DocuVieware1")) {
        DocuViewareAPI.RegisterOnTextSelected("DocuVieware1", function () { console.log("text selected"); });
    else {
        setTimeout(function () { RegisterOnTextSelectedOnDocuViewareAPIReady() }, 10);
document.addEventListener("DOMContentLoaded", function () {
}, false);