zoukankan      html  css  js  c++  java
  • 复制和粘贴的js代码(IE/FireFox/mozilla/ns)

    Jscript有些属性其实挺好的,可惜就是只是IE支持,比如复制和粘贴的属性

    下面这段复制和粘贴的JAVASCRIPT的代码倒是可以支持IE/FireFox/mozilla/ns,,老外站点上看来的

    只是在firefox下需要修改一下about:config的一个属性

    <script language="javascript" type="text/javascript">
    <!--
    function copy_clip(meintext)
    {
     if (window.clipboardData)
      {

      // the IE-manier
      window.clipboardData.setData("Text", meintext);

      // waarschijnlijk niet de beste manier om Moz/NS te detecteren;
      // het is mij echter onbekend vanaf welke versie dit precies werkt:
      }
      else if (window.netscape)
      {

      // dit is belangrijk maar staat nergens duidelijk vermeld:
      // you have to sign the code to enable this, or see notes below
      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

      // maak een interface naar het clipboard
      var clip = Components.classes['@mozilla.org/widget/clipboard;1']
             .createInstance(Components.interfaces.nsIClipboard);
      if (!clip) return;

      // maak een transferable
      var trans = Components.classes['@mozilla.org/widget/transferable;1']
              .createInstance(Components.interfaces.nsITransferable);
      if (!trans) return;

      // specificeer wat voor soort data we op willen halen; text in dit geval
      trans.addDataFlavor('text/unicode');

      // om de data uit de transferable te halen hebben we 2 nieuwe objecten
      // nodig om het in op te slaan
      var str = new Object();
      var len = new Object();

      var str = Components.classes["@mozilla.org/supports-string;1"]
             .createInstance(Components.interfaces.nsISupportsString);

      var copytext=meintext;

      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("Following info was copied to your clipboard:\n\n" + meintext);
      return false;
    }
    //-->
    </script>

    notes about security:

    a cause of the tight security settings in mozilla you have to sign the javascript to make it work another way is to change your firefox/mozilla settings

    to do this add this line to your prefs.js file in your firefox/mozilla user profile directory

    user_pref("signed.applets.codebase_principal_support", true);

    or change it from within the browser with calling the "about:config" page

  • 相关阅读:
    【机器学习】机器学习12个关键经验教训
    【机器学习】24个终极项目提升您的机器学习知识和技能
    2018-12-21-WPF-弹出-popup-里面的-TextBox-无法输入汉字
    2019-10-31-C#-dotnet-获取整个局域网的-ip-地址
    2018-11-26-win10-uwp-获取窗口的坐标和宽度高度
    2019-5-21-dotnet-core-使用-CoreRT-将程序编译为-Native-程序
    2019-5-21-Roslyn-使用-Directory.Build.props-管理多个项目配置
    2019-2-26-SublimeText-快速打开当前文件的文件夹
    2019-2-18-VisualStudio-给项目添加特殊的-Nuget-的链接
    2019-8-31-dotnet-如何在-Mock-模拟-Func-判断调用次数
  • 原文地址:https://www.cnblogs.com/luluping/p/1730699.html
Copyright © 2011-2022 走看看