问题
I am using the netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect') for firefox.
i am facing the problem for browser compatability for editor. we are using HTML EDITOR.
In IE all version cut, copy and paste is working for this editor.
when comes to mozilla, these are working only upto some versions only. it is not working in firefox 15 onwords....
when i right click, the cut, copy and paste are disabled. eventhough shotcut keys are also not working.
can any one know this? please clarify above issues ASAP.
we are using for this copy the selected text. here is a sample code for this:
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 ) ;
};
Thank you...
回答1:
From Mozilla's support pages;
Starting in Firefox 17 privileged code can not run in a web page anymore. In Firefox 15 you have to manually change a setting to enable it. You can bring that kind of functionality to an extension. Starting points: https://developer.mozilla.org/en-US/docs/Code_snippets/Interaction_between_privileged_and_non-privileged_pages
For beginners: https://developer.mozilla.org/en-US/docs/XUL_School/Getting_Started_with_Firefox_Extensions
More information: https://developer.mozilla.org/en-US/docs/Bypassing_Security_Restrictions_and_Signing_Code
Here you can find a (somewhat heated) discussion on the subject that has been going on for a couple of years :)
回答2:
I recommend ZeroClipboard as a workaround. You can select an element by ID and overlay it with a transparent flash video of the same size. Flash allows access to the clipboard so you can cut/copy things. If iThings aren't so much of a worry, it might be a decent option.
ZeroClipboard requires Flash version 9 or higher. So I would use swfobject to check for the required version first.
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:
we need to add some privileges using about:config with out quotation.
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");
来源:https://stackoverflow.com/questions/14809226/cut-copy-and-paste-is-not-working-for-firefox-15-onwords