Hello I was trying to get copying and pasting working in Firefox 2 but couldn’t get it to work, I get the error
Clipboard is not defined dhtmlXGrid_nxml.js (line 196)
I tried the usual tricks to enable clipboard, including setting, in about:config
signed.applets.codebase_principal_support = true
And the following in user.js:
user_pref(“capability.policy.policynames”, “allowclipboard”);
user_pref(“capability.policy.allowclipboard.sites”, “scbr.com”);
user_pref(“capability.policy.allowclipboard.Clipboard.cutcopy”, “allAccess”);
user_pref(“capability.policy.allowclipboard.Clipboard.paste”, “allAccess”);
But the error still occurs.
I have been looking around this area and I found an alternative solution that works well in Firefox, there are some details here:
developer.mozilla.org/en/docs/Us … _Clipboard
I modified the copy and paste methods in dhtmlXGrid_nxml.js as follows and now copying/pasting works in Firefox and better still it pops up a security dialogue asking whether or not you want to allow the site access to the clipboard, so no need to fiddle with all the config options.
------------------------------------------------------------------------------------------------------------------------------------------------
dhtmlXGridObject.prototype.toClipBoard=function(val){
if (window.clipboardData) {
window.clipboardData.setData(“Text”,val);
}
else {
netscape.security.PrivilegeManager.enablePrivilege(“UniversalXPConnect”)
var copytext = val;
var str = Components.classes["@mozilla.org/supports-string;1"].
createInstance(Components.interfaces.nsISupportsString);
if (!str) return false;
str.data = copytext;
var trans = Components.classes["@mozilla.org/widget/transferable;1"].
createInstance(Components.interfaces.nsITransferable);
if (!trans) return false;
trans.addDataFlavor(“text/unicode”);
trans.setTransferData(“text/unicode”, str, copytext.length * 2);
var clipid = Components.interfaces.nsIClipboard;
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid);
if (!clip) return false;
clip.setData(trans, null, clipid.kGlobalClipboard);
}
};
//------------------------------------------------------------------------------------------------------------------------------------------------
dhtmlXGridObject.prototype.fromClipBoard=function(){
if (window.clipboardData) {
return window.clipboardData.getData(“Text”)
}
else{
netscape.security.PrivilegeManager.enablePrivilege(“UniversalXPConnect”);
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);
if (!clip) return false;
var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
if (!trans) return false;
trans.addDataFlavor(“text/unicode”);
clip.getData(trans, clip.kGlobalClipboard);
var str = new Object();
var strLength = new Object();
trans.getTransferData(“text/unicode”, str, strLength);
if (str) str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
if (str) pastetext = str.data.substring(0, strLength.value / 2);
return pastetext;
}
};
Thanks for your code propositions, I incorporated this logic in main code branch.
Updated file for dhtmlxGrid 1.3 attached.
dhtmlxGrid_nxml.zip (4.19 KB)