<!--
{
  "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

[`string()`](/documentation/WebKit/WebDocumentText/string())

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

[`attributedString()`](/documentation/WebKit/WebDocumentText/attributedString())

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

### Selecting and deselecting text

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

Selects all the text in the web document.

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

Deselects the currently selected text in the web document.

[`selectedString()`](/documentation/WebKit/WebDocumentText/selectedString())

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

[`selectedAttributedString()`](/documentation/WebKit/WebDocumentText/selectedAttributedString())

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

### Text encoding

[`supportsTextEncoding()`](/documentation/WebKit/WebDocumentText/supportsTextEncoding())

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



---

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)