The answer is … you can’t! Well, generally speaking, that is.

Here are the reasons why:

  1. First things first, for security reasons, you cannot even simulate running the context menu’s Copy Image command.
  2. In Internet Explorer, you can copy a portion or all of the Canvas to an Image using document.body.createControlRange.
  3. In some later versions of Firefox, the ClipboardEvent lets you do copy an Image to clipboard.
  4. In Chrome, there is no way to do so except for some workaround using a littler helper called Flash.
  5. Then again, Flash won’t work in Safari browser.

With these findings, to provide the same consistency across browsers, it is best not to add this feature to your web application for consistency reasons which can bring confusion to some users who are not technically inclined why they will be forced to use certain browsers that only this feature works.

Issues arise when you want to copy text to the clipboard using javascript. Firefox provides a security measure which prevents you from doing it so a workaround has to be made for it to happen. I am using IE7 for my IE testing and in this version, it also has a security feature although less strict than Firefox. Whenever you browse to a new page that has a copy to clipboard function, a popup window prompts you asking if you want to allow the webpage to access your clipboard. Normally, you would choose no. But instances may require you to like if the site you are accessing is yours or related to your needs and you have the utmost trust that the script won’t harm your PC or something. Anyway, to provide copy to clipboard functionality using Javascript, I found this function in this site does the job by using a little .SWF file. You can download the file there or if you want to use Google App Engine, the code function below will do. It also works in Safari, IE, and Opera.

Related Posts Plugin for WordPress, Blogger...