Clipboard - Copy Image To Clipboard

M

Mahsha

<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>
 
T

Thomas 'PointedEars' Lahn

Mahsha said:
<html>
<head>
<title></title>

<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 `/'.

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

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


PointedEars
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top