在Firefox 19.0中从剪贴板获取数据

时间:2013-08-13 13:15:14

标签: firefox clipboard

我们从12.0升级到FF 19.0,剪贴板访问完全受限制,我无法从剪贴板获取数据。

在FF的早期版本中,以下内容曾经发挥作用。

  

netscape.security.PrivilegeManager.enablePrivilege( “UniversalXPConnect”);                   var clip = Components.classes [“@ mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);                   var trans = Components.classes [“@ mozilla.org/widget/transferable;1”]。createInstance(Components.interfaces.nsITransferable);

用例:

对于输入文本字段,当粘贴多行文本时,我想用我选择的分隔符替换默认空格字符作为分隔符。

例如:test1 \ n      TEST2 \ n      TEST3

在FF中的输入文本字段中粘贴此文本时, O / p见:test1 test2 test3 需要O / p:test1,test2,test3(当分隔符为','时)               test1; test; test3(当分隔符为';'时)

要求:

粘贴的文本应该在粘贴到文本字段之前进行修改,唯一的方法似乎是访问剪贴板。

我尝试了以下链接,但没有帮助。

 https://support.mozilla.org/en-US/questions/948379

 http://stackoverflow.com/questions/14809226/cut-copy-and-paste-is-not-working-for-firefox-15-onwords

我尝试修改用户pref以允许剪贴板无效。

  

user_pref(“capability.policy.policynames”,“allowclipboard”);

     

user_pref(“capability.policy.allowclipboard.sites”,mydomain);

     

user_pref( “capability.policy.allowclipboard.Clipboard.cutcopy”,   “allAccess”);

我不应该使用flash对象来访问剪贴板(ZClip或ZeroClipboard)。

感谢您的回复。提前致谢。

1 个答案:

答案 0 :(得分:1)

尝试这种方式:http://jsfiddle.net/kUEBs/3/,适用于firefox 23

<div style="border:1px solid grey;height:50px;" id="paste_ff" type="text" contenteditable></div>

<script type="text/javascript">
var pasteCatcher = document.getElementById('paste_ff');
document.getElementById('paste_ff').addEventListener('DOMSubtreeModified',function(){  
    if(pasteCatcher.children.length == 1){
        var text = pasteCatcher.innerHTML; console.log(text);   
        //text2  = text.replace(/\n/g, "___"); console.log(text);
        text2  = text.replace("<br>","____");
        if(text2 != text){
            pasteCatcher.innerHTML = text2;
            }
        }
    },false);
</script>