Clipboard

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{APIRef("Clipboard API")}}{{SecureContext_Header}}

The **Clipboard** interface of the Clipboard API provides read and write access to the contents of the system clipboard. This allows a web application to implement cut, copy, and paste features.

{{InheritanceDiagram}}

The system clipboard is exposed through the global {{domxref("Navigator.clipboard")}} property.

All of the Clipboard API methods operate asynchronously; they return a {{jsxref("Promise")}} which is resolved once the clipboard access has been completed. The promise is rejected if clipboard access is denied.

All the methods require a secure context. Additional requirements for using the API are discussed in the Security consideration section of the API overview topic.

Instance methods

_Clipboard is based on the {{domxref("EventTarget")}} interface, and includes its methods._

  • {{domxref("Clipboard.read()","read()")}}
  • : Reads the items on the system clipboard, returning a {{jsxref("Promise")}} that is fulfilled when the operation completes.

Each item is a {{domxref("ClipboardItem")}} that can contain several representations of the copied data, such as versions in HTML and text.

  • {{domxref("Clipboard.readText()","readText()")}}
  • : Requests text from the system clipboard, returning a {{jsxref("Promise")}} that is fulfilled with a string containing the clipboard's text once it's available.
  • {{domxref("Clipboard.write()","write()")}}
  • : Writes one or more {{domxref("ClipboardItem")}} objects to the system clipboard, returning a {{jsxref("Promise")}} that is fulfilled when the operation completes.
  • {{domxref("Clipboard.writeText()","writeText()")}}
  • : Writes text to the system clipboard, returning a {{jsxref("Promise")}} that is resolved once the text is fully copied into the clipboard.

Events

  • {{domxref("Clipboard.clipboardchange_event","clipboardchange")}} {{experimental_inline}}
  • : Fired when the system clipboard contents are changed in any way, for example via a system copy command, or via an API method such as {{domxref("Clipboard.writeText()")}}.

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("Document.execCommand()")}}