兼容所有浏览器的复制方法

说明:使用此方法 可以兼容所有浏览器 这是一个插件 flash 插件,之前调试了很久 出错,后来找到原因 是因为 没有调用 插件:ZeroClipboard 代码如下 [html] <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <link href="__PUBLIC__/css/public.css" rel="stylesheet" type="text/css" /> <link href="__PUBLIC__/css/PerFiles.css" rel="stylesheet" type="text/css" /> <link href="__PUBLIC__/css/mail.css" rel="stylesheet" type="text/css" /> <style type="text/css"> body { font-family:arial,sans-serif; font-size:9pt; } .my_clip_button { 150px; text-align:center; border:1px solid black; background-color:#ccc; margin:10px; padding:10px; cursor:default; font-size:9pt; } .my_clip_button.hover { background-color:#eee; } .my_clip_button.active { background-color:#aaa; } </style> <script type="text/javascript" src="__PUBLIC__/js/zeroclipboard/ZeroClipboard.js"></script> <script language="JavaScript"> var clip = null; ZeroClipboard.setMoviePath("__PUBLIC__/js/zeroclipboard/ZeroClipboard.swf"); function $(id) { return document.getElementById(id); } function init() { clip = new ZeroClipboard.Client(); clip.setHandCursor( true ); clip.addEventListener('load', function (client) { debugstr("Flash movie loaded and ready."); }); clip.addEventListener('mouseOver', function (client) { // update the text on mouse over clip.setText( $('user_name').value ); }); clip.addEventListener('complete', function (client, text) { debugstr("Copied text to clipboard: " + text ); }); clip.glue( 'd_clip_button', 'd_clip_container' ); } function debugstr(msg) { var p = document.createElement('p'); p.innerHTML = msg; $('d_debug').appendChild(p); } </script> </head> <body onLoad="init()"> <div class="main" id="main"> <div class="public"> <div class="public_title"> <div class="small_logo"><img src="__PUBLIC__/images/ico.png" alt=""/></div> </div> <div class="public_cont"> <!--不同的地方--> <div class="public_add"> <h3><a href="index.php?m=Index&a=index">我的推广<em class=""></em></a></h3> <h3><a href="index.php?m=Index&a=user_spread">用户消费</a><em class=""></em></h3> <h3><a href="index.php?m=Index&a=my_spread_url">推广链接</a><em class=""></em></h3> <ul class="public_add_ul"> <li class="seclet"><a href="index.php?m=Index&a=my_spread_url">推广链接</a></li> </ul> <div class="help" onClick="help();">使用帮助</div> </div> <!--不同的地方 end--> <div class="public_tab"> <div class="public_tab_con"> <table width="100%" border="0" class="public_table" id="public_table" > <tr> <th scope="row">推广链接:</th> <td>复制推广地址 或者推荐码 发送给企业用户,当注册成功一个企业用户赠送50积分,当企业用户消费 推广人会获得 一定比例分成,详情分成比例啊请参考推广分成:例如 一次消费1000 分成百分之10 一次消费5000 分成百分之15</td> </tr> <tr> <th scope="row">推广链接:</th> <td><input name="user_name" id="user_name" type="text" style="280px;" readonly value="{$apply}"/> 复制链接地址 <div id="d_clip_container" style="position:relative"> <div id="d_clip_button" class="my_clip_button"><b>Copy To Clipboard...</b></div> </div> </td> </tr> <tr> <th scope="row">推荐码:</th> <td><input name="user_name" id="user_name" type="text" style="280px;" readonly value="{$spread_code}"/> </td> </tr> </table> </body> </html> [/html]
原文地址:https://www.cnblogs.com/freefei/p/3234984.html