Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

javascript - Cut,Copy and paste is not working for firefox 15 onwords?

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( /
/g, '<br/>' ) ;
window.activeEditor._inserthtml( code ) ;
};

Thank you...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...