【问题标题】:Cut,Copy and paste is not working for firefox 15 onwords?剪切、复制和粘贴不适用于 Firefox 15 onwords?
【发布时间】:2013-02-20 19:29:46
【问题描述】:

我正在为 firefox 使用 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect')。

我正面临编辑器的浏览器兼容性问题。我们正在使用 HTML EDITOR。

在 IE 中,所有版本的剪切、复制和粘贴都适用于此编辑器。

对于 Mozilla,这些仅适用于某些版本。它在 Firefox 15 onwords 中不起作用....

当我右键单击时,剪切、复制和粘贴被禁用。即使shotcut键也不起作用。

有人知道吗?请尽快澄清以上问题。

我们用于此副本的选定文本。这是一个示例代码:

PasteText.prototype.execute = function()
{

netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
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');
clip.getData(trans,clip.kGlobalClipboard);
var str = new Object();
var len = new Object();
try {
    trans.getTransferData('text/unicode',str,len);
}
catch(error) { return; }
if (str) {
    if (Components.interfaces.nsISupportsWString) {
        str=str.value.QueryInterface(Components.interfaces.nsISupportsWString);
    } else if (Components.interfaces.nsISupportsString) {
        str=str.value.QueryInterface(Components.interfaces.nsISupportsString);
    } else {
        str = null;
    }
}

if (str) {
    var code = str.data.substring(0,len.value / 2);
}
code = code.replace( /\n/g, '<br/>' ) ;
window.activeEditor._inserthtml( code ) ;
};

谢谢...

【问题讨论】:

  • 为什么这个标签是“php”?

标签: javascript mozilla


【解决方案1】:

来自Mozilla's support pages

从 Firefox 17 开始,特权代码不能再在网页中运行。 在 Firefox 15 中,您必须手动更改设置才能启用它。您可以将此类功能引入扩展程序。起点:https://developer.mozilla.org/en-US/docs/Code_snippets/Interaction_between_privileged_and_non-privileged_pages

初学者:https://developer.mozilla.org/en-US/docs/XUL_School/Getting_Started_with_Firefox_Extensions

更多信息:https://developer.mozilla.org/en-US/docs/Bypassing_Security_Restrictions_and_Signing_Code

Here你可以找到关于这个主题的(有点激烈的)讨论已经持续了几年:)

【讨论】:

  • signed.applet.codebase_principal_support;是的,我已将此首选项名称更改为 TRUE。然后它适用于最高 Mozilla 15
  • @SachinMalmanchi This support ticket 似乎涵盖了您在该部分遇到的相同问题。
  • 还有其他偏好名称可以克服这个问题吗?
  • @SachinMalmanchi 我不知道解决方法,对不起,但我没有深入研究这个主题,所以你可能会得到其他答案。
【解决方案2】:

我推荐ZeroClipboard 作为解决方法。您可以通过 ID 选择一个元素,并用相同大小的透明 Flash 视频覆盖它。 Flash 允许访问剪贴板,因此您可以剪切/复制内容。如果 iThings 不是那么令人担心,它可能是一个不错的选择。

ZeroClipboard 需要 Flash 9 或更高版本。所以我会先使用swfobject 来检查所需的版本。

if (swfobject.hasFlashPlayerVersion('9')) {
    $.getScript('/js/ZeroClipboard.min.js', function(){
         ZeroClipboard.setMoviePath('/swf/ZeroClipboard10.swf');
         var clip = new ZeroClipboard.Client;
         clip.setCSSEffects(true);
         clip.setHandCursor(true);
         clip.glue('copy-elem-id', 'copy-elem-id-container');
         clip.addEventListener('onMouseDown', function(e){
             var copyText = $('#textbox-id').text();
             clip.setText(copyText);
         });
    });
}

【讨论】:

    【解决方案3】:

    我们需要使用 about:config 不带引号添加一些权限。

    user_pref("capability.policy.policynames", "allowclipboard"); user_pref("capability.policy.allowclipboard.sites", "https://www.mozilla.org"); user_pref("capability.policy.allowclipboard.Clipboard.cutcopy", "allAccess"); user_pref("capability.policy.allowclipboard.Clipboard.paste", "allAccess");

    【讨论】:

      猜你喜欢
      • 2021-04-05
      • 2011-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 2013-05-13
      • 2017-02-25
      相关资源
      最近更新 更多