Copy Text Or HTML To Clipboard – CopyJS

Category: Javascript , Text | September 24, 2021
Author:codingjlu
Views Total:813 views
Official Page:Go to website
Last Update:September 24, 2021
License:MIT

Preview:

Copy Text Or HTML To Clipboard – CopyJS

Description:

CopyJS is a tiny JavaScript library that allows you to copy plain text or HTML content to the clipboard.

How to use it:

1. Import the CopyJS library into the document.

<script src="copy.min.js"></script>

2. Copy plain text to the clipboard.

copyjs("Text to copy", {
  // options here
});

3. Copy HTML content to the clipboard.

copyjs('<h1 style="color:red;">Hello, world!</h1>', { 
  html: true 
});

4. Copy content from a selector (like a textarea).

copyjs("#text", {
  copyFromSelector: true,
  html: true
});

5. Determine whether to re-highlight what selected. Default: true.

copyjs("#text", {
  copyFromSelector: true,
  html: true,
  reSelect: false,
});

You Might Be Interested In:


Leave a Reply