jQuery Plugin To Copy/Paste/Select Text - jQlipboard

File Size: 472 KB
Views Total: 2823
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
jQuery Plugin To Copy/Paste/Select Text - jQlipboard

jQlipboard is a simple jQuery clipboard plugin for handling copy, cut, paste, and select (highlight) events on the web app.

How to use it:

1. Load the main script JQlipboard.js after jQuery.

<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/JQlipboard.js"></script>

2. Copy any content to the clipboard.

// "Copied!" is copied
$.copy( "Copied!" ) 

// "1234" is copied
$.copy( 1234 ) 

// "false" is copied
$.copy( false ) 

// '{"hello":"world"}' is copied
$.copy( {hello: "world"} ) 

// "2021-01-01T05:00:00.000Z" is copied
$.copy( new Date("1/1/2021") ) 

// "<div>Hello World</div>" is copied
$.copy( document.querySelector("div") ) 

// "12345678901234567890" is copied
$.copy( 12345678901234567890n ) 

// "Hello World" is copied
$.copy( {toString: function(){return "Hello World"} ) 

3. Or copy text within a container element.

<div id="demo">This text will be coppied</div>
$( '#demo' ).copy();

4. Cut selected text to clipboard.

// select
$( "input" ).select();

// cut
$.cut();

5. Cut text within an element to clipboard and remove the element

// cut
$( ".element" ).cut();

// cut & remove
$( ".element" ).copy().remove();

6. Remove selection ranges.

$.deselect()

7. Paste clipboard contents to text fields.

$( "input" ).focus();
$.paste();

8. Paste clipboard contents to elements.

$( ".element" ).paste();

9. Determine when the page will request permession to use the clipboard:

  • when needed (default)
  • immediate
$.jQlipboard({
  permissionPrompt: "when needed"
})

10. Determine whether to detect when you modify the clipboard on your own and to adjust the functions accordingly. Default: false.

$.jQlipboard({
  copyListener: true
})

Changelog:

v0.3 (2021-06-17)

  • Added cut & paste

2021-04-14

  • Revert "New way of detecting POJO"

2021-03-20

  • Better use of jQuery

2020-11-15

  • Improvement

2020-11-02

  • Cleanup JS.

2020-10-31


This awesome jQuery plugin is developed by DiriectorDoc. For more Advanced Usages, please check the demo page or visit the official website.