Home  >  Article  >  Web Front-end  >  zeroclipboard flash_javascript trick to copy to clipboard

zeroclipboard flash_javascript trick to copy to clipboard

WBOY
WBOYOriginal
2016-05-16 18:21:591030browse

The following are the implementation steps:
1- Reference files. After downloading, you will get two core files, ZeroClipboard.js and ZeroClipboard.swf, reference one of them in the project.


2- Loading ZeroClipboard object and implements the copy function.

Copy code The code is as follows:

//This step is very important, set the flash file reference path.
ZeroClipboard.setMoviePath('http://www.cnblogs.com/Scripts/ZeroClipboard/ZeroClipboard.swf');
//Create ZeroClipboard object
clip = new ZeroClipboard.Client();
clip.setHandCursor(true);
//Loading event, in the mouseOver event, transfer the content to be copied to the flahs file and save it
clip.addEventListener('mouseOver', function(client) {
clip.setText($('#IndInfo').val());
});
//A dialog box will pop up after successful copying
clip.addEventListener('complete', function(client, text ) {
alert("Copied text to clipboard:nn" text);
});
//Specify the object that implements the copy function
clip.glue('Copy');
/ /The following is the html object used
<%= Html.Hidden("IndInfo", ViewData["IndInfoFormat"].SafeString())%>



3- If it is local debugging, flash-based security mechanism requires some settings
http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html
Just enter the physical path of the flash file directly on the web page.

Download address http://www.jb51.net/jiaoben/28907.html
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn