TX Text Control .NET Server

Javascript: HypertextLinkCollection.add Method

Method|Introduced in 28.0

Description

Inserts a new hypertext link at the current input position.

Syntax

<void> HypertextLinkCollection.add(<string> text, <string> target, [<RequestHypertextLinkCallback> callback], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
text

Specifies the visible text of the hypertext link.

target

Specifies a string specifying to where the hypertext link points.

callback

Optional. Receives the added document link or null if no link could be added.

errorCallback

Optional. Is called when the operation failed with an error.

Examples

The following example demonstrates HypertextLinkCollection.add in a practical document-editing workflow. It inserts a new hypertext link at the current input position.

function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

TXTextControl.textParts.getMainText(function(mainText) {
    const hypertextLinks = mainText.hypertextLinks;
    hypertextLinks.add(
        "Quarterly report",
        "https://www.example.com/invoices/2026",
        function(result) {
            if (!result) {
                console.warn("No hypertext link was returned.");
                return;
            }
            
            console.log("add result:", result);
        },
        onTxError
    );
}, onTxError);