# Javascript: TextFrameCollection.addAnchored Method

> Creates and inserts a new text frame which is anchored to the specified text position. It has the specified horizontal alignment and a textflow which is given through the insertionMode parameter. Anchored text frames are moved with the text.

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: TextFrameCollection.addAnchored Method
- **627 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/textframecollection/addanchored-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/textframecollection/addanchored-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/textframecollection/addanchored-method/llms-full.txt

---

### Description

Creates and inserts a new text frame which is anchored to the specified text position. It has the specified horizontal alignment and a textflow which is given through the insertionMode parameter. Anchored text frames are moved with the text.

### Syntax

```javascript
<void> TextFrameCollection.addAnchored(<Size> size, <HorizontalAlignment> horizontalAlignment, <number> textPosition, <TextFrameInsertionMode> insertionMode, [<RequestTextFrameCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| size | The text frame's size in twips. |
| horizontalAlignment | Specifies the text frame's horizontal alignment. |
| textPosition | Specifies the text position at which the text frame is to be inserted. If -1 is specified, the text frame is inserted at the current input position. |
| insertionMode | Specifies how the text flow is handled. |
| callback | Optional. The newly created text frame object is returned via this callback function. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `TextFrameCollection.addAnchored` in a practical document-editing workflow. It creates and inserts a new text frame which is anchored to the specified text position. It has the specified horizontal alignment and a textflow which is given through the insertionMode parameter. Anchored text frames are moved with the text.

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

TXTextControl.textFrames.addAnchored(
    { width: 2880, height: 1440 },
    TXTextControl.HorizontalAlignment.Center,
    -1,
    TXTextControl.TextFrameInsertionMode.AsCharacter,
    function(textFrame) {
        if (!textFrame) {
            console.warn("No text frame was returned.");
            return;
        }
        
        console.log("add anchored result:", textFrame);
    },
    onTxError
);
```

---

## Nearby

- **Previous:** [TextFrameCollection Object](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/textframecollection/llms-full.txt)
- **Next:** [Javascript: TextFrameCollection.addAnchoredAtLocation Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/textframecollection/addanchoredatlocation-method/llms-full.txt)
