zoukankan      html  css  js  c++  java
  • JS复制内容到剪切板 (转)

    转载的内容

    <script type="text/javascript" language="javascript">
            //复制到剪切板js代码
            function copyToClipBoard(s) {
                //alert(s);
                if (window.clipboardData) {
                    window.clipboardData.setData("Text", s);
                    alert("已经复制到剪切板!"+ "
    " + s);
                } else if (navigator.userAgent.indexOf("Opera") != -1) {
                    window.location = s;
                } else if (window.netscape) {
                    try {
                        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                    } catch (e) {
                        alert("被浏览器拒绝!
    请在浏览器地址栏输入'about:config'并回车
    然后将'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 = s;
                    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("已经复制到剪切板!" + "
    " + s)
                }
            }</script>
    <script type="text/javascript" language="javascript">
            //复制到剪切板js代码
            function copyToClipBoard(s) {
                //alert(s);
                if (window.clipboardData) {
                    window.clipboardData.setData("Text", s);
                    alert("已经复制到剪切板!"+ " " + s);
                } else if (navigator.userAgent.indexOf("Opera") != -1) {
                    window.location = s;
                } else if (window.netscape) {
                    try {
                        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                    } catch (e) {
                        alert("被浏览器拒绝! 请在浏览器地址栏输入'about:config'并回车 然后将'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 = s;
                    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("已经复制到剪切板!" + " " + s)
                }
            }</script>
  • 相关阅读:
    Android 自定义seekbar中,thumb被覆盖掉一部分问题
    Android SeekBar实现音量调节
    Android 设置thumb图片大小
    Android 图片处理方法
    Android 三档自定义滑动开关,禁止点击功能的实现,用默认的seekbar组件实现
    Android SeekBar自定义使用图片和颜色显示
    Android 使控件各占屏幕的一半
    Android ExpandableListView使用+获取SIM卡状态信息
    Android的5样的调试信息
    Js创建对象的做法
  • 原文地址:https://www.cnblogs.com/SongYiJian/p/5891848.html
Copyright © 2011-2022 走看看