Clipboard - Copy Image To Clipboard

Discussion in 'Javascript' started by Mahsha, Jun 1, 2009.

  1. Mahsha

    Mahsha Guest

    <html>
    <head>
    <title></title>
    <script type="text/javascript">
    function fnCopy(objId) {
    var imgObj = document.getElementById('imgId');
    imgObj.contentEditable = 'true';
    var controlRange;
    if (document.body.createControlRange) {
    controlRange = document.body.createControlRange();
    controlRange.addElement(imgObj);
    controlRange.execCommand('Copy');
    alert("Copy image done");
    }
    imgObj.contentEditable = 'false';
    }
    </script>
    </head>

    <body>

    <div id="test1">
    <img id="imgId" src="http://www.google.com/intl/en_ALL/images/
    logo.gif" />
    </div>
    <a href="javascript:fnCopy('test1');">Copy Image</a>
    </body>
    </html>
    Mahsha, Jun 1, 2009
    #1
    1. Advertising

  2. Mahsha wrote:
    > <html>
    > <head>
    > <title></title>


    <http://www.w3.org/QA/Tips/good-titles>

    > <script type="text/javascript">
    > function fnCopy(objId) {
    > var imgObj = document.getElementById('imgId');


    var imgObj = document.getElementById(objId);

    > imgObj.contentEditable = 'true';


    The property value is supposed to be boolean, not string:

    img.contentEditable = true;

    <http://msdn.microsoft.com/en-us/library/ms537837(VS.85).aspx>

    Of course one should feature-test this property before one assigns to it.

    > var controlRange;


    There's no point in declaring the variable *here*.

    > if (document.body.createControlRange) {


    Insufficient feature test. Search for isMethod().

    > controlRange = document.body.createControlRange();


    var controlRange = document.body.createControlRange();

    > controlRange.addElement(imgObj);


    Missing feature test.

    > controlRange.execCommand('Copy');


    Missing feature test.

    > alert("Copy image done");


    Should be window.alert().

    > }
    > imgObj.contentEditable = 'false';


    imgObj.contentEditable = false;

    > }
    > </script>
    > </head>
    >
    > <body>
    >
    > <div id="test1">
    > <img id="imgId" src="http://www.google.com/intl/en_ALL/images/
    > logo.gif" />


    The #REQUIRED `alt' attribute is missing. Besides, what you have posted is
    neither Valid HTML nor Valid XHTML -- lose the `/'.

    <http://validator.w3.org/>

    > </div>
    > <a href="javascript:fnCopy('test1');">Copy Image</a>


    Don't. See the FAQ on `javascript:'.


    PointedEars
    Thomas 'PointedEars' Lahn, Jun 1, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TC
    Replies:
    0
    Views:
    705
  2. Terri I.
    Replies:
    0
    Views:
    561
    Terri I.
    Oct 9, 2003
  3. Replies:
    2
    Views:
    749
  4. Help: Copy Image to Clipboard

    , Sep 8, 2005, in forum: Javascript
    Replies:
    2
    Views:
    107
  5. Mahsha

    Clipboard - Copy Text To Clipboard

    Mahsha, Jun 1, 2009, in forum: Javascript
    Replies:
    3
    Views:
    632
    Thomas 'PointedEars' Lahn
    Jun 1, 2009
Loading...

Share This Page