识别剪切板中的数据并提交

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>识别剪切板中的数据并提交</title>
  </head>
  <body>
    <textarea id="myTextarea" name="content"></textarea>
    <button type="button" onclick="checkClipboard()">提交</button>

    <script>
      const myTextarea = document.getElementById('myTextarea');
      // 检测剪贴板中的文本数据
      function checkClipboard() {
        if (navigator.clipboard && navigator.clipboard.readText) {
          navigator.clipboard.readText().then((text) => {
            if (text) {
              myTextarea.value = text;
              console.log('已经检测到剪贴板中的文本数据并提交:', text);
            } else {
              alert('无数据!');
            }
          });
        } else {
          alert('该浏览器不支持读取剪贴板中的文本数据!');
        }
      }
    </script>
  </body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_43770056/article/details/131355487
今日推荐