X

LATEST #JQUERY NEWS

Copy Data to Clipboard Using jQuery


In this post, find jQuery solution to allow users to copy data to clipboard. This solution is quite handy when right click is disabled for your website and also text selection is also disabled. When text selection is disabled along with right click, it’s difficult for users to select the text and then copy it.

Here is the jQuery solution to copy data to clipboard using jQuery:

$(function() {
   $('.allowCopy').click(function() {
     $(this).focus();
     $(this).select();
     document.execCommand('copy');
   });
});

The above jQuery code will allow click events for all HTML controls with a CSS class “allowCopy” and then select the text and execute document.execCommand(‘copy’); command which will copy the data. Below is HTML code:

<input readonly type="text" value="Click Me To Copy" class="allowCopy noselect">

Here is the jQuery code to disable right click on your website:

$(function(){
   $(document).on("contextmenu",function(e){
      e.preventDefault();
   });
});

You can use following CSS class to disable text selection on your website:

.noselect {
  -webkit-touch-callout: none; 
  -webkit-user-select: none;   
  -khtml-user-select: none;    
  -moz-user-select: none;      
  -ms-user-select: none;      
  user-select: none;
}

Recently Published

article image
»

7 Responsive jQuery Dropdown Menu Plugins

Dropdown Menu Plugins Dropdown menus are mostly used for website ...

article image
»

20 Stylish and Modern jQuery Tooltip Plugins

jQuery Tooltip Plugins Tooltips are a great option for showing extra ...

article image
»

15 Newest jQuery plugins for responsive website

Due to the proliferation of smartphones and tablets, responsive ...

article image
»

How to use Redux with jQuery

State management is one of most integral parts of any software and a ...

article image
»

Fade HTML Table Row on Hover Using jQuery

HTML tables are the ideal choice for displaying data in tabular form. ...

article image
»

Drag and Drop HTML Table Rows Using jQuery

HTML tables are the preferred UI option for displaying data. Sorting, ...

article image
»

Top 5 Best JavaScript Template Engines

Template engines help in the decoupling of HTML and JavaScript code ...

article image
»

3 jQuery/JavaScript Plugins for Push Notifications

Push notifications started from the mobile business but this ...

article image
»

Create Smooth Animation Using jQuery’s “stop()”

Making Quick Work jQuery’s animate() method is a quick way to ...