aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/clipboard/writetext
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/clipboard/writetext
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/clipboard/writetext')
-rw-r--r--files/zh-cn/web/api/clipboard/writetext/index.html68
1 files changed, 68 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/clipboard/writetext/index.html b/files/zh-cn/web/api/clipboard/writetext/index.html
new file mode 100644
index 0000000000..e60e7204fe
--- /dev/null
+++ b/files/zh-cn/web/api/clipboard/writetext/index.html
@@ -0,0 +1,68 @@
+---
+title: Clipboard.writeText()
+slug: Web/API/Clipboard/writeText
+tags:
+ - API
+ - Clip
+ - Clipboard
+ - Clipboard API
+ - writeText
+translation_of: Web/API/Clipboard/writeText
+---
+<div>{{APIRef("Clipboard API")}}</div>
+
+<p>{{domxref("Clipboard")}} 接口的 <strong><code>writeText()</code></strong> 方法可以写入特定字符串到操作系统的剪切板。</p>
+
+<div class="note">
+<p><strong>Note:</strong> 规范要求在写入剪贴板之前使用 <a href="/en-US/docs/Web/API/Permissions_API">Permissions API</a> 获取“剪贴板写入”权限。但是,不同浏览器的具体要求不同,因为这是一个新的API。有关详细信息,请查看{{anch("Browser compatibility", "compatibility table")}} and {{SectionOnPage("/en-US/docs/Web/API/Clipboard", "Clipboard availability")}}。</p>
+</div>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">var <em>promise</em> = navigator.clipboard.writeText(<em>newClipText</em>)</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>newClipText</code></dt>
+ <dd>The {{domxref("DOMString")}} to be written to the clipboard.</dd>
+ <dt>
+ <h3 id="返回值">返回值</h3>
+ </dt>
+</dl>
+
+<p>一个{{jsxref("Promise")}} ,一旦剪贴板的内容被更新,它就会被解析。如果调用者没有写入剪贴板的权限,则拒绝写入剪切板(reject)</p>
+
+<h2 id="例子">例子</h2>
+
+<p>此示例将剪贴板的内容设置为字符串“&lt;empty clipboard&gt;”。</p>
+
+<pre class="brush: js">navigator.clipboard.writeText("&lt;empty clipboard&gt;").then(function() {
+ /* clipboard successfully set */
+}, function() {
+ /* clipboard write failed */
+});
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">注解</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Clipboard API','#h-clipboard-writetext-data','writeText()')}}</td>
+ <td>{{Spec2('Clipboard API')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.Clipboard.writeText")}}</p>