1

Possible Duplicate:
How to copy to the clipboard in JavaScript?

I need one help regards JavaScript. I used this script in asp.net website.

    <script type="text/javascript">
        function CopyToClip() {
            var imgControl = document.getElementById('imageControlWithImageToCopy');
            imgControl.contentEditable = 'true';
            var controlRange;

            if (document.body.createControlRange) {
                controlRange = document.body.createControlRange();
                controlRange.addElement(imgControl);
                controlRange.execCommand('Copy');
            }
            imgControl.contentEditable = 'false';
            return true;
        }
    </script>

This code for copying image (which is in an image control) to clipboard and it works fine in IE.

But this script is not working in Firefox & Chrome.

Please suggest any good solution to work in Firefox & Chrome

Community
  • 1
  • 1
Sajin
  • 203
  • 3
  • 9

2 Answers2

2

Sorry, but you can't copy stuff into the clipboard in Chrome or Firefox. Internet Explorer has a small hole that lets you do this, but it's the pretty much the only browser that supports that type of functionality any more.

There's a Flash hack to make this possible, but that's only for text, sorry.

Elliot Bonneville
  • 46,945
  • 19
  • 86
  • 120
0

Take a look at here. Google chrome doesn't support copy to clipboard any more. You might wanna look into flash possible options. Found this one one too, but no more development.

Jermin Bazazian
  • 1,812
  • 2
  • 16
  • 19
  • It won't help. These supports text only. We need solution for copying image to clipboard. – Sajin Apr 19 '12 at 04:55
  • Yes, most of the scripts supports text only. http://forums.mozillazine.org/viewtopic.php?f=25&t=1195035&start=0 The above site also discussing the same issue. The following site said related to security issues, http://kb.mozillazine.org/Granting_JavaScript_access_to_the_clipboard but this won't work in latest version of Mozilla. – Sajin Apr 20 '12 at 09:53