{"id":2810,"date":"2023-07-20T13:12:52","date_gmt":"2023-07-20T05:12:52","guid":{"rendered":"https:\/\/h5app.yimenapp.cn\/h5app\/?p=2810"},"modified":"2023-07-20T13:12:52","modified_gmt":"2023-07-20T05:12:52","slug":"webclipboard%e5%bc%95%e7%94%a8%e6%95%99%e7%a8%8b%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/h5app.yimenapp.cn\/h5app\/2023\/mianqiandabao\/2810\/","title":{"rendered":"webclipboard\u5f15\u7528\u6559\u7a0b\u4ecb\u7ecd"},"content":{"rendered":"<p>Web Clipboard\u5f15\u7528\u6559\u7a0b\uff1a\u539f\u7406\u4e0e\u8be6\u7ec6\u4ecb\u7ecd<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u5b66\u4e60Web\u526a\u8d34\u677f\uff08\u5373Clipboard API\uff09\u7684\u6982\u5ff5\u3001\u539f\u7406\u548c\u5982\u4f55\u5728Web\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u5b83\u3002Web\u526a\u8d34\u677f\u662f\u4e00\u79cd\u5141\u8bb8\u7528\u6237\u65b9\u4fbf\u5730\u5728\u7f51\u9875\u4e4b\u95f4\u590d\u5236\u548c\u7c98\u8d34\u6570\u636e\u7684\u529f\u80fd\uff0c\u4e3a\u5404\u79cd\u7c7b\u578b\u7684\u6570\u636e\u63d0\u4f9b\u4e86\u7b80\u5355\u7684\u8bfb\u5199\u63a5\u53e3\u3002<\/p>\n<p>\u76ee\u5f55:<\/p>\n<p>1. Web\u526a\u8d34\u677f\u7684\u539f\u7406<\/p>\n<p>2. Web\u526a\u8d34\u677fAPI\u7b80\u4ecb<\/p>\n<p>3. \u5982\u4f55\u4f7f\u7528Web\u526a\u8d34\u677f<\/p>\n<p>4. \u793a\u4f8b\uff1a\u5728Web\u5e94\u7528\u4e2d\u5b9e\u73b0\u590d\u5236\u7c98\u8d34\u529f\u80fd<\/p>\n<p>5. \u5b9e\u7528\u6280\u5de7\u548c\u6ce8\u610f\u4e8b\u9879<\/p>\n<p>6. \u53c2\u8003\u8d44\u6e90<\/p>\n<p>1. Web\u526a\u8d34\u677f\u7684\u539f\u7406<\/p>\n<p>\u526a\u8d34\u677f\u662f\u8ba1\u7b97\u673a\u4e2d\u4e00\u5757\u4e34\u65f6\u5b58\u50a8\u7a7a\u95f4\uff0c\u7528\u6237\u53ef\u4ee5\u5c06\u6570\u636e\u590d\u5236\u5230\u526a\u8d34\u677f\uff0c\u7136\u540e\u5c06\u5176\u7c98\u8d34\u5230\u5176\u4ed6\u4f4d\u7f6e\u3002\u5728Web\u5e94\u7528\u4e2d\uff0c\u526a\u8d34\u677f\u7684\u6838\u5fc3\u539f\u7406\u4e0e\u684c\u9762\u5e94\u7528\u7c7b\u4f3c\uff0c\u5373\u901a\u8fc7\u590d\u5236\uff08Ctrl + C\uff09\u548c\u7c98\u8d34\uff08Ctrl + V\uff09\u6765<a href=\"https:\/\/iosmianqian.yimenapp.com\/webclip-296.html\">iosapp\u514d\u8d39\u7b7e\u540d<\/a>\u64cd\u4f5c\u6570\u636e\u3002Web\u526a\u8d34\u677f\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5728\u7f51\u9875\u548c\u6d4f\u89c8\u5668\u4e4b\u95f4\u590d\u5236\u548c\u7c98\u8d34\u6570\u636e\u3002 <\/p>\n<p>2. Web\u526a\u8d34\u677fAPI\u7b80\u4ecb<\/p>\n<p>Web\u526a\u8d34\u677fAPI\u662f\u6307\u7531W3C\u5236\u5b9a\u7684\u4e00\u5957\u7528\u4e8e\u4e0e\u526a\u8d34\u677f\u8fdb\u884c\u4ea4\u4e92\u7684\u89c4\u8303\u3002\u8fd9\u4e9bAPI\u662f\u8de8\u6d4f\u89c8\u5668\u7684\uff0c\u5141\u8bb8Web\u5f00\u53d1\u4eba\u5458\u4ee5\u7f16\u7a0b\u7684\u65b9\u5f0f\u5904\u7406\u526a\u8d34\u677f\u64cd\u4f5c\u3002Clipboard API\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u529f\u80fd\uff1a<\/p>\n<p>&#8211; \u590d\u5236\u6587\u672c\u6570\u636e\u5230\u526a\u8d34\u677f<\/p>\n<p>&#8211; \u4ece\u526a\u8d34\u677f\u7c98\u8d34\u6587\u672c\u6570\u636e<\/p>\n<p>&#8211; \u590d\u5236\u56fe\u50cf\u6570\u636e\u5230\u526a\u8d34\u677f\uff08\u90e8\u5206\u6d4f\u89c8\u5668\u652f\u6301\uff09<\/p>\n<p>&#8211; \u5c06\u6587\u4ef6\u548cBlob\u5bf9\u8c61\u6dfb\u52a0\u5230\u526a\u8d34\u677f\uff08\u90e8\u5206\u6d4f\u89c8\u5668\u652f\u6301\uff09<\/p>\n<p>3. \u5982\u4f55\u4f7f\u7528Web\u526a\u8d34\u677f<\/p>\n<p>\u8981\u4f7f\u7528Web\u526a\u8d34\u677f\uff0c\u9996\u5148\u9700\u8981\u5728JavaScript\u4ee3\u7801\u4e2d\u83b7\u53d6\u526a\u8d34\u677f\u5bf9\u8c61\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u53d6\u526a\u8d34\u677f\u5bf9\u8c61\uff1a<\/p>\n<p>&#8220;`javascript<\/p>\n<p>navigator.clipboard<\/p>\n<p>&#8220;`<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u4f7f\u7528`writeText()`\u548c`readText()`\u65b9\u6cd5\u5728JavaScript\u4ee3\u7801\u4e2d\u8bfb\u5199\u526a\u8d34\u677f\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e24\u4e2a\u7b80\u5355\u7684\u4f7f\u7528\u793a\u4f8b\uff1a<\/p>\n<p>&#8220;`javascript<\/p>\n<p>\/\/ \u590d\u5236\u6587\u672c\u5230\u526a\u8d34\u677f<\/p>\n<p>async function copyTextToClipboard(text) {<\/p>\n<p>  try {<\/p>\n<p>    await navigator.clipboard.writeText(text);<\/p>\n<p>    console.log(&#8220;Text copied to clipboard!&#8221;);<\/p>\n<p>  } catch (err) {<\/p>\n<p>    console.error(&#8220;Error copying text: &#8220;, err);<\/p>\n<p>  }<\/p>\n<p>}<\/p>\n<p>\/\/ \u4ece\u526a\u8d34\u677f\u7c98\u8d34\u6587\u672c<\/p>\n<p>async function pasteTextFromClipboard() {<\/p>\n<p>  try {<\/p>\n<p>    const text = await navigator.clipboard.readText();<\/p>\n<p>    console.log(&#8220;Text pasted from clipboard: &#8220;, text);<\/p>\n<p>  } catch (err) {<\/p>\n<p>    console.error(&#8220;Error pasting text: &#8220;, err);<\/p>\n<p>  }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>4. \u793a\u4f8b\uff1a\u5728Web\u5e94\u7528\u4e2d\u5b9e\u73b0\u590d\u5236\u7c98\u8d34\u529f\u80fd<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684Web\u5e94\u7528\u793a\u4f8b\uff0c\u6f14\u793a\u5982\u4f55\u5b9e\u73b0\u81ea\u5b9a\u4e49\u7684\u590d\u5236\u548c\u7c98\u8d34\u6309\u94ae\u3002<\/p>\n<p>&#8220;`html<\/p>\n<\/p>\n<p>\n<p>\n<p>    button {<\/p>\n<p>      margin-bottom: 10px;<\/p>\n<p>    }<\/p>\n<\/p>\n<p>\n<p>Web Clipboard Demo<\/p>\n<p><button>Copy<\/button><\/p>\n<p><button>Paste<\/button><\/p>\n<p><textarea id=\"textArea\" rows=\"10\" cols=\"50\"><\/textarea><\/p>\n<\/p>\n<p>  function copyText() {<\/p>\n<p>    const textArea = document.getElementById(&#8220;textArea&#8221;);<\/p>\n<p>    navigator.clipboard.writeText(textArea.value);<\/p>\n<p>  }<\/p>\n<p>  async function pasteText() {<\/p>\n<p>    const textArea = document.getElementById(&#8220;textArea&#8221;);<\/p>\n<p>    const text = await navigator.clipboard.readText();<\/p>\n<p>    textArea.val<a href=\"https:\/\/iosmianqian.yimenapp.com\/webclip-861.html\">webclipper\u7b80\u60a6<\/a>ue = text;<\/p>\n<p>  }<\/p>\n<\/p>\n<\/p>\n<p>&#8220;`<\/p>\n<p>5. \u5b9e\u7528\u6280\u5de7\u548c\u6ce8\u610f\u4e8b\u9879<\/p>\n<p>&#8211; \u9700\u8981\u7528\u6237\u6388\u6743\uff1a\u6839\u636e\u6d4f\u89c8\u5668\u5b89\u5168\u7b56\u7565\uff0c\u8bbf\u95ee\u526a\u8d34\u677f\u64cd\u4f5c\u53ef\u80fd\u9700\u8981\u7528\u6237\u7684\u660e\u786e\u6388\u6743\u3002\u56e0\u6b64\uff0c\u5728\u4f7f\u7528Clipboard API\u65f6\uff0c\u8bf7\u786e\u4fdd\u5904\u7406\u53ef\u80fd\u51fa\u73b0\u7684\u6743\u9650\u95ee\u9898\u3002<\/p>\n<p>&#8211; \u517c\u5bb9\u6027\u95ee\u9898\uff1a\u867d\u7136Clipboard API\u5728\u4e3b\u6d41\u6d4f\u89c8\u5668<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-03\/30\/18\/03657743327.jpg\" \/><\/figure>\n<\/p>\n<p>\u4e2d\u7684\u652f\u6301\u8f83\u597d\uff0c\u4f46\u5728\u65e7\u7248\u672c\u7684\u6d4f\u89c8\u5668\u4e2d\u53ef\u80fd\u5b58\u5728\u517c\u5bb9\u6027\u95ee\u9898\u3002\u5728\u90e8\u7f72Web\u526a\u8d34\u677f\u529f\u80fd\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u8fdb\u884c\u5145\u5206\u7684\u517c\u5bb9\u6027\u6d4b\u8bd5\u3002<\/p>\n<p>6. \u53c2\u8003\u8d44\u6e90<\/p>\n<p>&#8211; [Clipboard API and events](https:\/\/w3c.github.io\/clipboard-apis\/)<\/p>\n<p>&#8211; [MDN Web Docs &#8211; Clipboard API](https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Clipboard_API)<\/p>\n<p>&#8211; [Can I use &#8211; Clipboard API](https:\/\/caniuse.com\/clipboard)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Web Clipboard\u5f15\u7528\u6559\u7a0b\uff1a\u539f\u7406\u4e0e\u8be6\u7ec6\u4ecb\u7ecd\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u5b66\u4e60Web\u526a\u8d34\u677f\uff08\u5373Clipboard API\uff09\u7684\u6982\u5ff5\u3001\u539f\u7406\u548c\u5982\u4f55\u5728Web\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u5b83\u3002Web\u526a\u8d34\u677f\u662f\u4e00\u79cd\u5141\u8bb8\u7528\u6237\u65b9\u4fbf\u5730\u5728<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[5672,5239,5671,759,4117],"topic":[],"class_list":["post-2810","post","type-post","status-publish","format-standard","hentry","category-mianqiandabao","tag-ios","tag-5239","tag-5671","tag-759","tag-4117"],"_links":{"self":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts\/2810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/comments?post=2810"}],"version-history":[{"count":0,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts\/2810\/revisions"}],"wp:attachment":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/media?parent=2810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/categories?post=2810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/tags?post=2810"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/topic?post=2810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}