Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Image to clipboard 2

Status
Not open for further replies.

birney29

Programmer
Oct 11, 2001
140
0
0
GB
Hi,

i have to create a button in my application, that uses javascript to copy and image to the clipboard (windows machine). Has anyone got any advice / sample code that would help achive this?

Thanks



Kenneth Birney
User Interface Programmer
Scottish Police
 
I use this for copying text to the clipboard...Could be a start for you...

Code:
javascript:
function HighlightAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
if (document.all&&copytoclip==1){
therange=tempval.createTextRange()
therange.execCommand("Copy")
}
}
code behind:
Me.cmdCopy.Attributes.Add("OnClick", "javascript:HighlightAll('Timer.txtTotalTime')")
 
I'm not sure you can achieve what your goal with JavaScript. There are 2 methods you can use to interact with the clipboard as far as I know: the clipboardData object and the dataTransfer object. Both objects use the same methods, which are getData and setData. However, I believe both methods are only capable of getting/setting text or URLs. If you find a solution to your problem, please post back. I'd be very interested to see how it works.
 
Try this:
Code:
<script>
function copyImg(id){
  var r = document.body.createControlRange();
  r.add(document.getElementById(id));
  r.select();
  r.execCommand("COPY");
}
</script>
<body onload="copyImg('myimg')">
<img src="image.jpg" id="myimg">
</body>

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Works a treat. nice one, thanks

Kenneth Birney
User Interface Programmer
Scottish Police
 
Adam, you always seem to have the obscure answers that nobody else knows :)

Have another star.

-kaht

banghead.gif
 
Thanks!

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top