<small id='1YnKF'></small><noframes id='1YnKF'>

      <tfoot id='1YnKF'></tfoot>
      • <bdo id='1YnKF'></bdo><ul id='1YnKF'></ul>

    1. <legend id='1YnKF'><style id='1YnKF'><dir id='1YnKF'><q id='1YnKF'></q></dir></style></legend>

      1. <i id='1YnKF'><tr id='1YnKF'><dt id='1YnKF'><q id='1YnKF'><span id='1YnKF'><b id='1YnKF'><form id='1YnKF'><ins id='1YnKF'></ins><ul id='1YnKF'></ul><sub id='1YnKF'></sub></form><legend id='1YnKF'></legend><bdo id='1YnKF'><pre id='1YnKF'><center id='1YnKF'></center></pre></bdo></b><th id='1YnKF'></th></span></q></dt></tr></i><div id='1YnKF'><tfoot id='1YnKF'></tfoot><dl id='1YnKF'><fieldset id='1YnKF'></fieldset></dl></div>

        在 chrome 中,使用 window.Clipboard 对象,有没有办法捕获粘贴的文本?

        时间:2023-10-02

                <tbody id='OHI71'></tbody>
                <bdo id='OHI71'></bdo><ul id='OHI71'></ul>

                <tfoot id='OHI71'></tfoot>

                <small id='OHI71'></small><noframes id='OHI71'>

                <legend id='OHI71'><style id='OHI71'><dir id='OHI71'><q id='OHI71'></q></dir></style></legend>
                <i id='OHI71'><tr id='OHI71'><dt id='OHI71'><q id='OHI71'><span id='OHI71'><b id='OHI71'><form id='OHI71'><ins id='OHI71'></ins><ul id='OHI71'></ul><sub id='OHI71'></sub></form><legend id='OHI71'></legend><bdo id='OHI71'><pre id='OHI71'><center id='OHI71'></center></pre></bdo></b><th id='OHI71'></th></span></q></dt></tr></i><div id='OHI71'><tfoot id='OHI71'></tfoot><dl id='OHI71'><fieldset id='OHI71'></fieldset></dl></div>

                  本文介绍了在 chrome 中,使用 window.Clipboard 对象,有没有办法捕获粘贴的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  您可以捕获图像.我想弄清楚如何捕获文本.出于安全原因,我猜没有,但我想确定一下.

                  You can capture an image. I am trying to figure out how to capture text. I'm guessing there isn't, for security reasons, but I wanted to make sure.

                  还有这些东西的参考吗?window.Clipboard 对象不是 v8 引擎的一部分,它是 chrome 浏览器的一部分,我找不到它的官方文档.

                  Also is there a reference for this stuff? window.Clipboard object isn't part of the v8 engine, it's a part of the chrome browser and I can't find official documentation for it.

                  推荐答案

                  在您链接的代码中有一个 pasteHandler 函数,其内容如下:

                  In the code you linked there is a pasteHandler function with the following:

                  // Get the items from the clipboard
                          var items = e.clipboardData.items;
                          if (items) {
                              // Loop through all items, looking for any kind of image
                              for (var i = 0; i < items.length; i++) {
                                  if (items[i].type.indexOf("image") !== -1) {
                                      // We need to represent the image as a file,
                                      var blob = items[i].getAsFile();
                                      // and use a URL or webkitURL (whichever is available to the browser)
                                      // to create a temporary URL to the object
                                      var URLObj = window.URL || window.webkitURL;
                                      var source = URLObj.createObjectURL(blob);
                  
                                      // The URL can then be used as the source of an image
                                      createImage(source);
                                  }
                              }
                          }
                  

                  Chrome 开发者框架告诉我 items[i] 是 DataTransferItem (参考)

                  Chrome developer frame is telling me that items[i] is a DataTransferItem (reference)

                  在参考页面上,我看到了一个 kind 属性和一个 getAsString() 方法.后者似乎需要一个接收文本作为参数的回调函数.因此,要使用上述脚本处理文本值,您可以修改我链接的部分,如下所示:

                  On the reference page I see a kind property and a getAsString() method. The latter seems to require a callback function that receives the text as a parameter. So to handle text values using the above script you might modify the section I linked as follows:

                  // Get the items from the clipboard
                          var items = e.clipboardData.items;
                          if (items) {
                              // Loop through all items, looking for any kind of image
                              for (var i = 0; i < items.length; i++) {
                                  if (items[i].type.indexOf("image") !== -1) {
                                      // We need to represent the image as a file,
                                      var blob = items[i].getAsFile();
                                      // and use a URL or webkitURL (whichever is available to the browser)
                                      // to create a temporary URL to the object
                                      var URLObj = window.URL || window.webkitURL;
                                      var source = URLObj.createObjectURL(blob);
                  
                                      // The URL can then be used as the source of an image
                                      createImage(source);
                                  } 
                                  if (items[i].kind === "string"){
                                      items[i].getAsString(function(s) {
                                          alert(s);
                                      });
                                  }
                              }
                          }
                  

                  这篇关于在 chrome 中,使用 window.Clipboard 对象,有没有办法捕获粘贴的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:javascript - 如何将 div 内容复制到另一个页面 下一篇:使用 CSS 或 Javascript 复制/剪切时从文本中删除样式

                  相关文章

                1. <tfoot id='OJlK8'></tfoot>
                    <bdo id='OJlK8'></bdo><ul id='OJlK8'></ul>

                    <small id='OJlK8'></small><noframes id='OJlK8'>

                  1. <legend id='OJlK8'><style id='OJlK8'><dir id='OJlK8'><q id='OJlK8'></q></dir></style></legend>

                      <i id='OJlK8'><tr id='OJlK8'><dt id='OJlK8'><q id='OJlK8'><span id='OJlK8'><b id='OJlK8'><form id='OJlK8'><ins id='OJlK8'></ins><ul id='OJlK8'></ul><sub id='OJlK8'></sub></form><legend id='OJlK8'></legend><bdo id='OJlK8'><pre id='OJlK8'><center id='OJlK8'></center></pre></bdo></b><th id='OJlK8'></th></span></q></dt></tr></i><div id='OJlK8'><tfoot id='OJlK8'></tfoot><dl id='OJlK8'><fieldset id='OJlK8'></fieldset></dl></div>