Class Clipboard
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
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.
[Value("Clipboard")]
public class Clipboard : EventTarget
- Inheritance
-
Clipboard
- Inherited Members
Remarks
The system clipboard is exposed through the global Clipboard property.
All of the Clipboard API methods operate asynchronously; they return a 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.
Constructors
Clipboard()
public Clipboard()
Methods
Read(ClipboardUnsanitizedFormats)
The read() method of the Clipboard interface requests a copy of the clipboard's contents, fulfilling the returned {{jsxref("Promise")}} with the data.
[Value("read")]
public Task<List<ClipboardItem>> Read(ClipboardUnsanitizedFormats formats = null)
Parameters
formatsClipboardUnsanitizedFormats
Returns
- Task<List<ClipboardItem>>
A {{jsxref("Promise")}} that resolves with an array of ClipboardItem objects containing the clipboard's contents.
Remarks
The method can in theory return arbitrary data (unlike ReadText(), which can only return text).
Browsers commonly support reading text, HTML, and PNG image data.
-Clipboard API
-Unblocking clipboard access on web.dev
-Unsanitized HTML in the Async Clipboard API on developer.chrome.com
-ReadText()
-WriteText(string)
-Write(List<ClipboardItem>)
ReadText()
The readText() method of the Clipboard interface returns a {{jsxref("Promise")}} which fulfills with a copy of the textual contents of the system clipboard.
[Value("readText")]
public Task<string> ReadText()
Returns
- Task<string>
A Promise that resolves with a string containing the textual contents of the clipboard.Returns an empty string if the clipboard is empty, does not contain text, or does not include a textual representation among the objects representing the clipboard's contents.
Remarks
NOTE
To read non-text contents from the clipboard, use the Read(ClipboardUnsanitizedFormats) method instead.
You can write text to the clipboard using WriteText(string).
-Clipboard API
-Image support for Async Clipboard article
-Read(ClipboardUnsanitizedFormats)
-WriteText(string)
-Write(List<ClipboardItem>)
Write(List<ClipboardItem>)
The write() method of the Clipboard interface writes arbitrary ClipboardItem data such as images and text to the clipboard, fulfilling the returned {{jsxref("Promise")}} on completion.
This can be used to implement cut and copy functionality.
[Value("write")]
public Task<GlobalObject.Undefined> Write(List<ClipboardItem> data)
Parameters
dataList<ClipboardItem>
Returns
- Task<GlobalObject.Undefined>
A Promise which is resolved when the data has been written to the clipboard.
Note that if the underlying OS does not support multiple native clipboard items on the system clipboard, then only the first ClipboardItem in the array is written.The promise is rejected if the clipboard is unable to write to the clipboard.
Remarks
The method can in theory write arbitrary data (unlike WriteText(string), which can only write text).
Browsers commonly support writing text, HTML, and PNG image data.
-Clipboard API
-Image support for Async Clipboard article
-WriteText(string)
-Read(ClipboardUnsanitizedFormats)
-ReadText()
WriteText(string)
The writeText() method of the Clipboard interface writes the specified text to the system clipboard, returning a {{jsxref("Promise")}} that is resolved once the system clipboard has been updated.
[Value("writeText")]
public Task<GlobalObject.Undefined> WriteText(string data)
Parameters
datastring
Returns
- Task<GlobalObject.Undefined>
A Promise that is resolved once the clipboard's contents have been updated.