<!--
{
  "availability" : [
    "macOS: 10.3.0 - 10.14.0"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WebDocumentText",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(pl)WebDocumentText"
  },
  "title" : "WebDocumentText"
}
-->

# WebDocumentText

`WebDocumentText` is an optional protocol for document view objects that display text. This protocol defines methods for accessing document content as strings, and methods for text selection. Classes that adopt this protocol should also adopt [`WebDocumentView`](/documentation/WebKit/WebDocumentView) and inherit from `NSView`.

```
protocol WebDocumentText : NSObjectProtocol
```

## Topics

### Getting document content

[`func string() -> String!`](/documentation/WebKit/WebDocumentText/string())

Returns the entire content of the web document as a string.

[`func attributedString() -> NSAttributedString!`](/documentation/WebKit/WebDocumentText/attributedString())

Returns the entire content of the web document as an attributed string.

### Selecting and deselecting text

[`func selectAll()`](/documentation/WebKit/WebDocumentText/selectAll())

Selects all the text in the web document.

[`func deselectAll()`](/documentation/WebKit/WebDocumentText/deselectAll())

Deselects the currently selected text in the web document.

[`func selectedString() -> String!`](/documentation/WebKit/WebDocumentText/selectedString())

Returns the currently selected text in the web document as a string.

[`func selectedAttributedString() -> NSAttributedString!`](/documentation/WebKit/WebDocumentText/selectedAttributedString())

Returns the currently selected text in the web document as an attributed string.

### Text encoding

[`func supportsTextEncoding() -> Bool`](/documentation/WebKit/WebDocumentText/supportsTextEncoding())

Returns a Boolean value that indicates whether the web document supports text encoding.

## Relationships

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)