Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2003
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copying an image

    Hi,
    Is there a way to copy an image onto the clipboard? I tried using ExecCommand but it seems it can only copy text.

    Any ideas will be appreciated.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If in its own window:

    alt & PrtScrn

    Paste in Paint or other Image Tool

  • #3
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    But that will copy the whole screen...
    Shawn

  • #4
    New Coder
    Join Date
    Jul 2003
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry for my vague description. I meant is there a way to copy an image by clicking a link?

  • #5
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I've never hear of it...

    You mean that a code?
    <a href="#null" onClick="CopyImage()">
    Your looking for something like that? (No that won't work, lol)
    Shawn

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you trying to copy the image to the clipboard so that you can move it elsewhere? If so, you can use something like this (IE-only):

    Code:
    //img is a reference to an <img> element
    function copyImage(img) {
    event.dataTransfer.setData("URL", img.src);
    }
    
    //sample function usage
    function placeElement(container) {
    var imgsrc = event.dataTransfer.getData("URL");
    var newNode = document.createElement("img");
    newNode.setAttribute("src", imgsrc);
    container.appendChild(newNode);
    }
    Hope that helps!

    Happy coding!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •