January 30, 2014 2:35 pm

How to copy text to Clipboard using jQuery

In this tutorial I am going to show you how to copy text in clipboard without ctrl+c and ctrl+v I have used jQuery Clipboard plugin (zclip) to perform this task. The JavaScript clipboard functionality is disabled by the most of the browser due to security risk so this plugin use a dynamic flash file.

How to copy text to Clipboard using jQuery

Usage

It’s very simple and short code to understand and easy to integrate:

jQuery library and zclip library include to handle copy procedure.

jQuery

jQuery to trigger library:

Here is the main logic we used a swf file which use flash action script to copy text because modern browsers disabled copy to clipboard so we used flash file for reference script used to create flash action script available here.

HTML text box and link:

All together

Here we create complete procedure with jQuery, CSS and HTML:

I hope it helps you guys please give your feedback in comments.

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.


Tutorial Categories:
  • Matthew

    But how do we attach the swf object for dynamically created elements ???

    • huzoorbux

      You don’t need to attach swf file just give its path in jQuery like this it will work itself path:”ZeroClipboard.swf”,.

  • Many thanks for your article

    I monetized some functional

  • LiuXing

    I can’t copy text to clipboard, I don’t know why?

    Please help me.

    I have already copy above tutorial code and link jquery.zclip.js and ZeroClipboard.swf.

  • Nahuel Esteban Castro

    Is there any possibility that the text is copied without pressing the button.
    Thank very much the code above is great.

  • kamal

    where is the flash plugin.I unable to download it

  • Does support Opera browser?

    p.s
    works flawlessly, I tried it now, thank you

  • Raghbendra Nayak

    Its working fine great thanks…..

  • techfuse12

    Demo not working with Chrome

  • zfdo

    Works fine. tk

  • Chan

    Hi, the script what I have downloaded from this site is not working in chrome(latest)/IE10. but there were no errors in script (when I click the CopyNow link, the text is not copied to clipboard). Could you pls tell me what could be the reason.

  • Nagaraju Kakaraparthi

    Hi, it not working Mozilla firefox. I think flash plugin problem. how to resolve it ?

  • Nilesh Daldra

    if i need to integrate on multiple buttons then???and that button are generated with ajax call..so how can i implement on this.

    my buttons like

    Copy

    Copy

    Copy

    Copy

    Copy