Javascript DOM generated with content copied to the clipboard

    createCopy(id) {
      var text = document.getElementById(id);
      if (document.body.createTextRange) {
          var range = document.body.createTextRange();
          range.moveToElementText(text);
          range.select();
      } else if (window.getSelection) {
          var selection = window.getSelection();
          var range = document.createRange();
          range.selectNodeContents(text);
          selection.removeAllRanges();
          selection.addRange(range);
      } else {
          alert("none");
      }
      document.execCommand('Copy','false',null);
    }

Ctrl + V can be used to perform the copy operation is very useful! ! !

Published 15 original articles · won praise 5 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_32654773/article/details/104694511