Am working on clipboard (Copy/Paste) functionality, i could able to copy the selected image to clipboard using IE but unable to do using Firefox 3.0.8 it has some security issues.The following javascript function copies the selected image to the Clipboard iN IE but not in Firefox
function CopyToClipboard()
{
var div = document.getElementById('croppedImage');
div.contentEditable = 'true';
var controlRange;
if (document.body.createControlRange)
{
controlRange = document.body.createControlRange();
controlRange.addElement(div);
controlRange.execCommand('Copy');
}
div.contentEditable = 'false';
}
Could anyone provide the javascript function such that Firefox can copy the selected image to the clipboard.
problem with image copy to clipboard in Firefox
-
- Posts: 2
- Joined: April 13th, 2009, 12:47 am
- DanRaisch
- Moderator
- Posts: 127246
- Joined: September 23rd, 2004, 8:57 pm
- Location: Somewhere on the right coast
Re: problem with image copy to clipboard in Firefox
Moving to Web Development.
- trolly
- Moderator
- Posts: 39851
- Joined: August 22nd, 2005, 7:25 am
Re: problem with image copy to clipboard in Firefox
Did you read this? http://kb.mozillazine.org/Granting_Java ... _clipboard
Normally the access to the clipboard is disabled due to security reasons.
Normally the access to the clipboard is disabled due to security reasons.
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
-
- Posts: 2
- Joined: April 13th, 2009, 12:47 am
Re: problem with image copy to clipboard in Firefox
After following the security previlages and setting the security policy files as mentioned in the url. I need the javascript function for Firefox.
In IE
function CopyToClipboard()
{
var div = document.getElementById('croppedImage');
div.contentEditable = 'true';
var controlRange;
if (document.body.createControlRange)
{
controlRange = document.body.createControlRange();
controlRange.addElement(div);
controlRange.execCommand('Copy');
}
div.contentEditable = 'false';
}
in the above javasacript document.body.createControlRange only works for IE i need the alterantive for Firefox. Is there any JS function which takes image to copy in clipboard.
In IE
function CopyToClipboard()
{
var div = document.getElementById('croppedImage');
div.contentEditable = 'true';
var controlRange;
if (document.body.createControlRange)
{
controlRange = document.body.createControlRange();
controlRange.addElement(div);
controlRange.execCommand('Copy');
}
div.contentEditable = 'false';
}
in the above javasacript document.body.createControlRange only works for IE i need the alterantive for Firefox. Is there any JS function which takes image to copy in clipboard.
- trolly
- Moderator
- Posts: 39851
- Joined: August 22nd, 2005, 7:25 am
Re: problem with image copy to clipboard in Firefox
I guess that's impossible.
Here is a solution with a supporting flash object. I do not know if they support images.
http://javascript.internet.com/forms/cl ... -copy.html
http://www.jeffothy.com/weblog/clipboard-copy/
An Addon:
https://addons.mozilla.org/en-US/firefox/addon/243
I found this code (probably the same or similar as in the addon) but it will ask for elevated privileges and it may have some faults due to its old date (2004):
Here is a solution with a supporting flash object. I do not know if they support images.
http://javascript.internet.com/forms/cl ... -copy.html
http://www.jeffothy.com/weblog/clipboard-copy/
An Addon:
https://addons.mozilla.org/en-US/firefox/addon/243
I found this code (probably the same or similar as in the addon) but it will ask for elevated privileges and it may have some faults due to its old date (2004):
Code: Select all
// This is importent but it's not noted anywhere
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
// create interface to the clipboard
var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
if (!clip) return;
// create a transferable
var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
if (!trans) return;
// specify the data we wish to handle. Plaintext in this case.
trans.addDataFlavor('text/unicode');
// To get the data from the transferable we need two new objects
var str = new Object();
var len = new Object();
var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);
var copytext=meintext;
str.data=copytext;
trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);
var clipid=Components.interfaces.nsIClipboard;
if (!clip) return false;
clip.setData(trans,null,clipid.kGlobalClipboard);
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.