• 万能的js复制按钮


    这是模仿优酷视频分享的js复制按钮,兼容各种浏览器


     <!--复制按钮js-->
    <script>
    function copyToClipboard(txt) {
        if (window.clipboardData) {
            window.clipboardData.clearData();
            window.clipboardData.setData("Text",document.getElementById(txt).value);
        } else if (navigator.userAgent.indexOf("Opera") != -1) {
            //do nothing      
        } else if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch (e) {
                alert("被浏览器拒绝!\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signed.applets.codebase_principal_support'设置为'true'");
            }
            var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
            if (!clip)   return;
            var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
            if (!trans) return;
            trans.addDataFlavor('text/unicode');
            var str = new Object();
            var len = new Object();
            var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
            var copytext = txt;
            str.data = copytext;
            trans.setTransferData("text/unicode", str, copytext.length * 2);
            var clipid = Components.interfaces.nsIClipboard;
            if (!clip)   return false;
            clip.setData(trans, null, clipid.kGlobalClipboard);
        }
        alert("你已经成功复制本地址,请直接粘贴推荐给你的朋友!");
    }
    </script>

    *********************************************************************************************

    使用:
    <!--分享对话框-->
               <div class="share" >
      <div class="sharetop"></div>
      <div class="sharebord">
      <h4>  分享给站外好友</h4>
    <div class="item"><span class="label">  视频地址 : </span> <input type="text" id="link1" value="http://www.moredoo.com/10002" /><button onclick="javascript:copyToClipboard('link1');">复制</button></div>
    <h4>  把视频贴到Blog或BBS</h4>
    
    
    <div class="item"><span class="label">  flash地址: </span> 
    <input type="text" id="link2" value="http://www.moredoo.com/10002" />
    <button onclick="javascript:copyToClipboard('link2');">复制</button></div>
    
    
    <div class="item"><span class="label">  html代码 : </span> 
    <input  id="link3" type="text" value='<embed src="http://www.moredoo.com/10002" 
    
    
    allowFullScreen="true" quality="high" width="480" height="400" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash"></embed>' />
    
    
    <button onclick="javascript:copyToClipboard('link3');">复制</button></div></div>
    
    
    <div class="sharebutom">

    效果如下



    效果:
  • 相关阅读:
    Eclipse相关问题
    分词工具比较(转)
    package-info.java文件详解
    如何在大量jar包中搜索特定字符
    eclipse插件在线发布发布和版本更新(web site) 转
    Peer Code Reviews Made Easy with Eclipse Plug-In
    Eclipse中Ant的配置与测试 转
    astyle 使用说明
    Eclipse远程调试出现“JDWP Transport dt_socket failed to initialize”的解决方案
    记录一个中括号的问题
  • 原文地址:https://www.cnblogs.com/y0umer/p/2809522.html
Copyright © 2020-2023  润新知