"JavaScript" Copy to Clipboard feature (support for various browsers currently)

Source: Internet
Author: User

This demo supports a variety of browser replication, pro-Test available (Ie8,ie9,ie10, Firefox, Google).

Zeroclipboard (:https://github.com/zeroclipboard/zeroclipboard) is used in this demo.

This demo must be in the server environment, the browser directly open invalid.

This demo requires the introduction of 3 files: Jquery.min.js, ZeroClipboard.min.js, and zeroclipboard.swf.

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "UTF-8"><title>Copy to Clipboard demo</title><Scripttype= "Text/javascript"src= "/webtest/js/jquery.min.js"></Script><Scripttype= "Text/javascript"src= "/webtest/js/zeroclipboard.min.js"></Script></Head><Body>    <inputtype= "button"value= "Copy current page URL"class= "My_copy" ></Body><Scripttype= "Text/javascript">$(function() {    varURL=window.location.href; Try{//Support ZeroclipboardZeroclipboard.config ({swfpath:"/webtest/js/zeroclipboard.swf" } ); $(". My_copy"). each (function(i) {varClient= NewZeroclipboard ($ ( This)); Client.on ("Copy", function(event) {varClipboard=Event.clipboarddata; Clipboard.setdata ("Text/plain", URL); Alert ('the current page link has been copied to the Clipboard! '); //clipboard.setdata ("text/html", "<b>copy me!</b>");                  //clipboard.setdata ("Application/rtf", "{\\rtf1\\ansi\n{\\b Copy me!}}");                });    }); }Catch(e) {//Zeroclipboard not supported        $(". My_copy"). each (function(i) {$ ( This). On ("Click", function(){                varRes=Window.clipboardData.setData ("Text", encodeURI (URL)); if(res) {alert ('the collection link has been copied to the Clipboard! ');                    }                            });    }); }    })</Script></HTML>

"JavaScript" Copy to Clipboard feature (support for various browsers currently)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.