zoukankan      html  css  js  c++  java
  • IE6, firefox 点击复制到剪切板功能

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <script>
                var id;
                function setCopy (id) {
                    var con = document.getElementById(id).innerHTML;
                    //window.clipboardData.setData("Text",con);
                    if(window.clipboardData){
                        window.clipboardData.clearData();
                        window.clipboardData.setData("Text", con);
                        alert("广告代码复制成功!");
                    } else if(window.netscape){     //Firefox
                        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 = con;
                        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>
            <body>
                <p ><xmp id="code"><a href="http://blog.163.com/ybbqg@126/blog/{$link}">请输入广告展示的内容!</a></xmp></p>
                <a href="http://blog.163.com/ybbqg@126/blog/#" onclick="setCopy('code');return false;" class="btn01" target="_self">复制此链接网址</a>
            </body>
    </html>

  • 相关阅读:
    构造函数的继承
    创建一个不被销毁的空间 闭包小应用
    如何在Linux上恢复误删除的文件或目录
    一文详解 Ansible 自动化运维
    Shell 脚本编程最佳实践
    10 分钟看懂 Docker 和 K8S!
    BGP路由协议详解(完整版)
    浅析 Linux 中的零拷贝技术
    2020年DevOps工程师入门指南
    一条更新的SQL如何执行
  • 原文地址:https://www.cnblogs.com/ybbqg/p/2399671.html
Copyright © 2011-2022 走看看